Java – wait() on servlet throws an exception

I run a web application on the JBoss application server, and I'm trying to implement event library response from the server

To achieve this, I use the servlet class Wait () and notify(). Basically, there is an Ajax request. The servlet blocks and waits until there is an event on the server. If so, notify. Net is triggered on the servlet

The problem is that when I wait on the servlet (1000 * 60), I get:

Servlet.service() for servlet ProcessesServlet threw exception: java.lang.IllegalMonitorStateException

Can I even execute wait () on the httpservlet class?

Solution

You must have ownership before waiting for an object

This is usually done using synchronized statements

synchronized (obj) {
        try {
            obj.wait(someTime);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>