Grokking Java Interview Questions
Vote

0% completed

​

Interruption and Shutdown

Thread packer = new Thread(() -> { while (true) { try { packNextOrder(); Thread.sleep(100); } catch (InterruptedException e) { // nothing to do } } }); packer.start(); packer.interrupt();

The last line asks the packer thread to stop, and the thread continues as if nothing had happened. The request did arrive. The code caught it, did nothing, and began the next round.

Java has no safe way for one thread to force another one to end. A thread can only send a request, and the receiving code must cooperate

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content