Article View: aus.computers.java
Article #398Re: THREADS AND SYNCHRONISATION
From: qteemoi
Date: Sun, 03 Dec 2000 00:00
Date: Sun, 03 Dec 2000 00:00
70 lines
3343 bytes
3343 bytes
run the code that you've juz written????
it doesn't work, i believe there are errors.....
hm..can't quite remember wat errors popped up though
Paul Murray wrote:
> "Qteemoi" <qteemoi@alphalink.com.au> wrote in message
> news:3A265709.C295849B@alphalink.com.au...
> > haha..i would be, but u see thats the problem, i dun quite understand
> > anything of it to be more specific.....i dun think i can quite grasp the
> > concept...everytime i think of a thread i think of a process....
>
> A thread is like a process that runs within an operating system "process".
> When you run "java.exe", there is one windows process (a java virtual
> machine), but this JVM may run several java "threads".
>
> A thread, essentally, is a stack context - a current point of execution.
> When any line of code is getting executed, some thread is executing.
>
> So where do the threads come from?
>
> As I understand it ... java.exe is a bit of "C" code. It starts up a Java
> Virtual Machine (which lives in some DLSs or the equivalent), then it tells
> the JVM to kick off a thread that starts at the "main" method of the class
> you passed as a parameter.
>
> Now you can make up threads of your own and kick them off. From your POV as
> a java programmer, these all run simultaneously. To make a thread, do a
> Thread t = new Thread();
>
> To kick it off, you do a
> t.start().
>
> Once you do that, the thread will start running. 'Course, you can't simply
> go new Thread(); You either subclasds the thread object, or more commonly
> construct it with an instance of a Runnable
>
> class Counter implements Runnable {
> final int myNum;
> Counter(int n) {myNum = n; }
> public void run() {
> for(int i = 0; i<100; i++) {
> System.out.println("I am Counter " + myNum + ", and this is
> iteration " + i);
> }
> }
> }
>
> public class foo {
> public static void main(String[] av) {
> for(int i = 0; i<10;i++) {
> Counter c = new Counter(i);
> Thread t = new Thread(c);
> t.start();
> }
> }
> }
>
> Now if you run this, all 10 threads will run at once and make a jumble on
> system.out. Try it.
>
> Once you've done that, we can diuscuss synchonisation, or you might have
> enough of a start now to work it out on your own. Note that the bahaviour of
> wait() and notify() can be subtle, so yo may need to come back here to talk
> about it.
>
> --------------------------------------------------------------
> Repent! Quit your job! Slack off!
> http://www.users.bigpond.com/pmurray
> ICQ: 26066755
Technical Details
Message-ID:
<3A2B1875.FFA3394D@alphalink.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3A22F646.F7CD61C9@alphalink.com.au> <UXlV5.146676$e5.87865@newsfeeds.bigpond.com> <3A265709.C295849B@alphalink.com.au> <ai_V5.150449$e5.92887@newsfeeds.bigpond.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,606181f3a363975d X-Google-Attributes: gid10d6db,public From: qteemoi <qteemoi@alphalink.com.au> Subject: Re: THREADS AND SYNCHRONISATION Date: 2000/12/03 Message-ID: <3A2B1875.FFA3394D@alphalink.com.au> X-Deja-AN: 700530568 Content-Transfer-Encoding: 7bit References: <3A22F646.F7CD61C9@alphalink.com.au> <UXlV5.146676$e5.87865@newsfeeds.bigpond.com> <3A265709.C295849B@alphalink.com.au> <ai_V5.150449$e5.92887@newsfeeds.bigpond.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Trace: 3 Dec 2000 20:10:58 GMT, 202.161.110.97 MIME-Version: 1.0 Newsgroups: aus.computers.java