Threads in java

A

abhishekG

hi
I am facing problem in Threads in java. I have studied threads and know
the theory of it. But I just cant get started. It would be great if I
can get some sample codes showing the use of wait(), notify(), sleep()
.. The code should have a number of threads (say 2-3) and each thread is
running.

Thanks
 
R

Robert Klemme

hi
I am facing problem in Threads in java. I have studied threads and know
the theory of it. But I just cant get started. It would be great if I
can get some sample codes showing the use of wait(), notify(), sleep()
. The code should have a number of threads (say 2-3) and each thread is
running.

Did you browse through the tutorial? AFAIK there are some examples in
[1]. Also, you can look at the source code of java.util.concurrent.*.

Kind regards

robert


[1] http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html
 
A

abhishekG

Thanks a lot Robert.
Wil go through the link and let u know if it works

Thanks
Robert said:
hi
I am facing problem in Threads in java. I have studied threads and know
the theory of it. But I just cant get started. It would be great if I
can get some sample codes showing the use of wait(), notify(), sleep()
. The code should have a number of threads (say 2-3) and each thread is
running.

Did you browse through the tutorial? AFAIK there are some examples in
[1]. Also, you can look at the source code of java.util.concurrent.*.

Kind regards

robert


[1] http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

abhishekG said:
I am facing problem in Threads in java. I have studied threads and know
the theory of it. But I just cant get started. It would be great if I
can get some sample codes showing the use of wait(), notify(), sleep()
. The code should have a number of threads (say 2-3) and each thread is
running.

If you are new to coding with threads then stay away from
wait and notify.

start, join and sleep are easy to use.

If you need slightly more advanced stuff then use
the new java.util.concurrent package instead of doing
it yourself.

Arne
 
T

Thomas Hawtin

Arne said:
If you are new to coding with threads then stay away from
wait and notify.

start, join and sleep are easy to use.

No. Don't use sleep. Even as a joke. You might think your code works
fine with sleep, but not even the Java library code does.
If you need slightly more advanced stuff then use
the new java.util.concurrent package instead of doing
it yourself.

If you possibly can.

If you want to learn about threads in Java 1.5+, I suggest starting with
"Java Concurrency in Practice" by Brian Goetz, Joshua Bloch, Joseph
Bowbeer, Doug Lea, David Holmes, Tim Peierls.

http://www.amazon.co.uk/dp/0321349601/ref=sr_11_1/202-5739469-5649426

Tom Hawtin
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Thomas said:
No. Don't use sleep. Even as a joke. You might think your code works
fine with sleep, but not even the Java library code does.

I am not quite clear what you mean.

Are you saying that sleep has a bug in all Java implementations
(SUN, IBM, BEA etc.) ?

Or are you saying that can read the contents of my hard drive
by telepathy and see that my usage of sleep does not match the
documented semantics of sleep ?

Or ?

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,085
Members
48,773
Latest member
Kaybee

Latest Threads

Top