Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Thread

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my book they say:
1) You can�t restart a dead thread
2) You can call the methods of a dead thread
How can i call the methods of a dead thread, when i call the start methoed i executes the code in the run methoed that�s it, what did they mean with statement 2 ???
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A thread is an object like any other. The special feature is that you can invoke the start method of a thread to spawn a new thread tha performs whatever tasks are defined in the run method. However, you can only take advatange of this once. Once you've started a thread, it can never be started again.
However, if your thread object has other methods, such as doIt(), you can invoke this method explicitly at any time, just as you would for any other object. This can be done even after you have started a thread and it has completed.
I hope that helps,
Corey
 
Frank Jacobsen
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Corey McGlone i now know what they mean now !
Can you also answer me on this topic ???
Reading from a socket:
try {

Socket sock = new Socket("magnesium" , 5505)
InputStream instr = sock.getInputStream();
int b = instr.read();
System.out.println("Im happy");
}
Now, as i understand,if magnesium has not yet written anything, however, the read() call has to wait.
Thats off course the fact that most IO have implemted some synchronized code, and my program above step out off the Running state an into the blocked state !!!
But whar happens i magnesium never writes anything, and the synchronized code in InputStream
newer call notify() or notify all(), will my program above be in the block state for ever, until i turn off the power off my NT, or will it timeout after some time, or what will happen ???
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as far as i know you will stay in blocked state forever....
unless the ServerSocket closes or qnother kind of IOException occurs (perhaps interrupted() is getting called).
for non blocking network connection check the new IO in jdk 1.4 in the java.nio package.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic