File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Thread questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread questions" Watch "Thread questions" New topic
Author

Thread questions

Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
Hi,
Thread questions:
Q.1 I don't understand interrupt() and internal flag and when should I use it?
Q.2 What does "No thread can make another thread yield" mean?
Q.3 Given:
public class MyRunnable implements Runnable
{
public void run()
{
//some code here
}
}
What is the proper way to create and start this thread?
Ans: new Thread(new MyRunnable()).start();
Why does it need to add new Thread as prefix?
Q.4 Given:
public class MyT extends Thread
{
public void run()
{
try
{
for(int i=1; i<5; i++)<br /> {<br /> System.out.print(i + " ");<br /> if(i>2)
interrupt();
sleep(1000);
if(interrupted())
break;
}
}
catch(InterruptedException e)
{
System.out.print("Caught");
}
}
}
Assume another object creates an instance of this Thread and starts it. Why does the outcome is:
1 2 3 caught
Thanks a lot.
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread questions