I'm running a web app in Jboss application server and I'm trying to implement an event base response from the server.
To accomplish that I'm using .wait() and .notify() on the servlets class. Basicly there is an Ajax request, the servlet blocks with wait
until there is an event on the server and if so notify
is fired on the servlet.
The problem is when I do wait(1000*60) on the Servlet I get:
Servlet.service() for servlet ProcessesServlet threw exception: java.lang.IllegalMonitorStateException
Is it even possible to do a wait() on a HttpServlet class?
Before you wait on an object, you must take ownership.
This is usualy done with a synchronized statement.
synchronized (obj) {
try {
obj.wait(someTime);
} catch (Throwable e) {
e.printStackTrace();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With