Start of a new thread in Java
class AddThread extends Thread {
private int add(int a, int b)
{
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return a + b;
}
public void run() {
int result = add(3, 5);
System.out.println("result: " + result);
}
}
AddThread thread = new AddThread();
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
System.out.println("main thread");
//output:
//main thread
//result: 8
- Log in to post comments