Closed companycy closed 6 years ago
I prefer not to encourage the use of Thread.sleep()
even in simple examples like this.
Instead, I'd be more comfortable stating in a comment something to the effect of:
workerThread.start();
// Enqueue more jobs, etc.
// Shutdown the worker when finished
worker.end(true);
Agree. Please update the example.
Updated the example.
Sometimes, there may be issue if worker.end(true) takes effect before workerThread.run(). Below exception is thrown:
Exception in thread "Thread-0" java.lang.IllegalStateException: This WorkerImpl is shutdown at net.greghaines.jesque.worker.WorkerImpl.run(WorkerImpl.java:258) Disconnected from the target VM, address: '127.0.0.1:64449', transport: 'socket' at java.lang.Thread.run(Thread.java:745)