and please explain the following code as wellpublic void run()implement Runnable Thanks!!!
backgroundThread = new Thread(this); //construct a thread object backgroundThread.start(); //thread object call method start() to start a thread. public void run() //The run() is a method of the Runnable interface. // construt a thread may implements Runnable interface that need implements the run() method //or extends a thread.
Some help please! protected Thread backgroundThread;public static void start() { if ( backgroundThread==null ) { backgroundThread = new Thread(); backgroundThread.start(); } }
public void run() { System.out.println("good"); Runnable doLater = new Runnable() { public void run() { System.out.println("not good"); } }; SwingUtilities.invokeLater(doLater); backgroundThread=null; }public static void main(String[] args) throws IOException { URL l = new URL("http://www.shef.ac.uk"); start(); }Why the programming doesn't go throw the public void run()? Prefer some help in Chinese!
The class that implements the Runnable interface is regarded as the same Type and meanwhile it would be accepted as the sole constructor parameter to be a target whose run method will then be called after the start method is invoked
something seems wrong in your run method try to remove the Runnable block and test it
Thx for all. Seems i have solved the problem. And could someone give me some sample code of resume, pause a thread?
directly call the method on the thread instance but deprecated, not recommended,such as stop,suspend alike due to deadlock-prone
Thanks!!!
//construct a thread object
backgroundThread.start();
//thread object call method start() to start a thread.
public void run()
//The run() is a method of the Runnable interface.
// construt a thread may implements Runnable interface that need implements the run() method
//or extends a thread.
protected Thread backgroundThread;public static void start()
{
if ( backgroundThread==null ) {
backgroundThread = new Thread();
backgroundThread.start();
}
}
public void run()
{
System.out.println("good");
Runnable doLater = new Runnable()
{
public void run()
{
System.out.println("not good");
}
};
SwingUtilities.invokeLater(doLater);
backgroundThread=null;
}public static void main(String[] args) throws IOException
{
URL l = new URL("http://www.shef.ac.uk");
start();
}Why the programming doesn't go throw the public void run()? Prefer some help in Chinese!
and meanwhile it would be accepted as the sole constructor parameter to be a target
whose run method will then be called after the start method is invoked
try to remove the Runnable block and test it
Seems i have solved the problem.
And could someone give me some sample code of resume, pause a thread?
but deprecated, not recommended,such as stop,suspend alike due to deadlock-prone