Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Threads in java

Thread view: 
abhishekG - 13 Oct 2006 10:07 GMT
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
Robert Klemme - 13 Oct 2006 10:21 GMT
> 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
Pawel Szulc - 13 Oct 2006 10:22 GMT
>> 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.

this almost sounds like some homework you have to make for 2morrow....
abhishekG - 13 Oct 2006 10:26 GMT
Thanks a lot Robert.
Wil go through the link and let u know if it works

Thanks

> > hi
> > I am facing problem in Threads in java. I have studied threads and know
[quoted text clipped - 11 lines]
>
> [1] http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html
Arne Vajhøj - 14 Oct 2006 02:42 GMT
> 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
Thomas Hawtin - 14 Oct 2006 13:34 GMT
>> 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
[quoted text clipped - 6 lines]
>
> 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
Arne Vajhøj - 14 Oct 2006 17:31 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.