Thread View: aus.computers.java
8 messages
8 total messages
Started by Qteemoi
Tue, 28 Nov 2000 00:00
THREADS AND SYNCHRONISATION
Author: Qteemoi
Date: Tue, 28 Nov 2000 00:00
Date: Tue, 28 Nov 2000 00:00
3 lines
567 bytes
567 bytes
Can sum1 tell me more about threads and synchronisation thanx
Re: THREADS AND SYNCHRONISATION
Author: Paul Murray
Date: Wed, 29 Nov 2000 00:00
Date: Wed, 29 Nov 2000 00:00
10 lines
1086 bytes
1086 bytes
"Qteemoi" <qteemoi@alphalink.com.au> wrote in message news:3A22F646.F7CD61C9@alphalink.com.au... > Can sum1 tell me more about threads and synchronisation I have a sample applet on my 'page. Can you be more specific? -------------------------------------------------------------- Repent! Quit your job! Slack off! http://www.users.bigpond.com/pmurray ICQ: 26066755
Re: THREADS AND SYNCHRONISATION
Author: Qteemoi
Date: Fri, 01 Dec 2000 00:00
Date: Fri, 01 Dec 2000 00:00
26 lines
1525 bytes
1525 bytes
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 a line of executions??....for example the dining philosophers..... i dun understand why they have each philosopher as a thread.....can u explain it??.... as for synchronisation...they refer to the word "LOCK" a lot....wat do they mean when they use that word.......... thanx Paul Murray wrote: > "Qteemoi" <qteemoi@alphalink.com.au> wrote in message > news:3A22F646.F7CD61C9@alphalink.com.au... > > Can sum1 tell me more about threads and synchronisation > > I have a sample applet on my 'page. Can you be more specific? > > -------------------------------------------------------------- > Repent! Quit your job! Slack off! > http://www.users.bigpond.com/pmurray > ICQ: 26066755
Re: THREADS AND SYNCHRONISATION
Author: Paul Murray
Date: Sat, 02 Dec 2000 00:00
Date: Sat, 02 Dec 2000 00:00
66 lines
3176 bytes
3176 bytes
"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
Re: THREADS AND SYNCHRONISATION
Author: 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
Re: THREADS AND SYNCHRONISATION
Author: Paul Murray
Date: Tue, 05 Dec 2000 00:00
Date: Tue, 05 Dec 2000 00:00
17 lines
1529 bytes
1529 bytes
"qteemoi" <qteemoi@alphalink.com.au> wrote in message news:3A2B1875.FFA3394D@alphalink.com.au... > 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 Oooh, that's not a lot of help. I just typed that code into mail, didn't compile it, so I expected errors. Sorry to say this, but if you can't debug a pair of 10-line methods, you probably shouldn't be fooling with threads just yet. Cheers! -------------------------------------------------------------- Repent! Quit your job! Slack off! http://www.users.bigpond.com/pmurray ICQ: 26066755
Re: THREADS AND SYNCHRONISATION
Author: qteemoi
Date: Tue, 05 Dec 2000 00:00
Date: Tue, 05 Dec 2000 00:00
23 lines
1585 bytes
1585 bytes
oh okay...well thats alwayz nice to hear.. kick me while i'm down..=( but thanx for your effort to help anywayz Paul Murray wrote: > "qteemoi" <qteemoi@alphalink.com.au> wrote in message > news:3A2B1875.FFA3394D@alphalink.com.au... > > 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 > > Oooh, that's not a lot of help. I just typed that code into mail, didn't > compile it, so I expected errors. Sorry to say this, but if you can't debug > a pair of 10-line methods, you probably shouldn't be fooling with threads > just yet. > > Cheers! > > -------------------------------------------------------------- > Repent! Quit your job! Slack off! > http://www.users.bigpond.com/pmurray > ICQ: 26066755
Re: THREADS AND SYNCHRONISATION
Author: Paul Murray
Date: Wed, 06 Dec 2000 00:00
Date: Wed, 06 Dec 2000 00:00
38 lines
2207 bytes
2207 bytes
Not worry <g>. Really - there's not a lot to it and you shouldn't have difficulty fixing up and making it work. -- -------------------------------------------------------------- Repent! Quit your job! Slack off! http://www.users.bigpond.com/pmurray ICQ: 26066755 "qteemoi" <qteemoi@alphalink.com.au> wrote in message news:3A2DE7DA.ACF4A3B8@alphalink.com.au... > oh okay...well thats alwayz nice to hear.. > kick me while i'm down..=( > but thanx for your effort to help anywayz > > Paul Murray wrote: > > > "qteemoi" <qteemoi@alphalink.com.au> wrote in message > > news:3A2B1875.FFA3394D@alphalink.com.au... > > > 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 > > > > Oooh, that's not a lot of help. I just typed that code into mail, didn't > > compile it, so I expected errors. Sorry to say this, but if you can't debug > > a pair of 10-line methods, you probably shouldn't be fooling with threads > > just yet. > > > > Cheers! > > > > -------------------------------------------------------------- > > Repent! Quit your job! Slack off! > > http://www.users.bigpond.com/pmurray > > ICQ: 26066755 >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads