views:

96

answers:

2

Hello

I have this problem:

I have a few threads which access one object with synchronized(Object) { ... }

But sometimes this exception is raised:

execute: java.util.concurrent.RejectedExecutionException

Why? And what should I do with it?

Thanks

A: 

Nevermind, I've been reading old log file instead of new one. There is no such exception being raised when I use synchronized()

Andrey
+1  A: 

That exception is meant to be raised by Executor.execute - you certainly shouldn't be seeing it just by accessing objects in a synchronized block.

Have a look at the rest of the stack trace to work out exactly where it's occurring, and look at the message to see if that gives you any more information about why you're getting it. As Todd commented, it would usually be due to something like a full work queue.

For example, ThreadPoolExecutor will throw this exception if the queue is uses to buffer tasks to be run refuses to accept more items. This usually indicates that your system is overloaded, or you've misconfigured the executor.

Jon Skeet
Yes, thanks, I have mistaken
Andrey