gresrun / jesque

An implementation of Resque in Java.
http://gresrun.github.io/jesque
Apache License 2.0
628 stars 131 forks source link

Add sleep before worker.end(true) in main thread #135

Closed companycy closed 6 years ago

companycy commented 6 years ago

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)

gresrun commented 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);
companycy commented 6 years ago

Agree. Please update the example.

gresrun commented 6 years ago

Updated the example.