June 2018
Beginner
722 pages
18h 47m
English
And here is how this class can be used to create two child threads—one user thread and another a daemon thread—exactly as we have done before:
Thread thr1 = new Thread(new ARunnable(1, 4));thr1.start();Thread thr2 = new Thread(new ARunnable(11, 14));thr2.setDaemon(true);thr2.start();try { TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) { e.printStackTrace();}System.out.println("Main thread exists");
If we run the preceding code, the result will be the same as running threads based on a class that extends Thread.
Read now
Unlock full access