Threads
Visit us here and  you will find
much more tips!
Receive our  newsletter with new tips!  Almost 6,000 subscribers (by June 2001) can not be wrong! 
They read our tips every week! 
 To subscribe to The Java FAQ Daily send empty e mail to:
javafaq tips subscribe@topica.com
  or visit at:
http://www.topica.com/lists/javafaq tips/
 Threads
Can anyone please explain the difference between the two types: green threads
and native threads?
Answer: Green threads is thread mechanism implemented in JVM itself. 
It is blind and can run on any OS, so actually all threads are run in one 
native thread and scheduling is up to JVM. This is disadvantageously for 
SMP systems, since only one processor can serve Java application.
Native threads is a mechanism based on OS threading mechanism. This allows 
to use features of hardware and OS. For example,there is IBM s JDK for 
AIX that supports native threads. The perfomance of applications 
can be highly imploved by this.
 Q: If a thread object has quit from run loop, how can I restart the thread object? (
I don t want to use some flags with wait/notify method to simulate restarting).
I try to use start() method, but it doesn t work.
Answer: No   Threads can t be restarted. You have to either loop with a wait/notify or
create a new Thread.
  
J. Skeet
I m having trouble getting sleep to work properly. It seems to just return
immediately, and not sleep for the requested time. Is there some trick I need to know
about? The docs say that sleep takes an argument in milli seconds, but sleep(10000)
seems to return immediately.
Answer:  It can happen if another thread interrupts your sleeping thread. 
sleep(10000) says that it just can sleep 10 sec if nobody needs it. That is reason why
you do
try{     
    sleep(10000);
}
catch(InterruptedException x){
    //do smth here
file:///F|/a_jsite/350_tips/threads.htm (1 of 4) [2001 07 08 11:25:00]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved