Synchronization using application object gets IllegalStateException

Hello,

I use a separate thread to update a table in a tab sheet, and every once in a while my application gets this:


17:34:45 INFO  [WebappClassLoader]
 Illegal access: this web application instance has been stopped already.  Could not load com.itmill.toolkit.data.util.IndexedContainer$1.  The eventual following stack trace 
is caused by an error thrown for debugging purposes as well as to attempt 
to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1244)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at com.itmill.toolkit.data.util.IndexedContainer$IndexedContainerProperty.<init>(IndexedContainer.java:1176)
	at com.itmill.toolkit.data.util.IndexedContainer.getContainerProperty(IndexedContainer.java:219)
	at com.itmill.toolkit.ui.AbstractSelect.getContainerProperty(AbstractSelect.java:726)
	at com.itmill.toolkit.ui.Table.refreshRenderedCells(Table.java:1308)
	at com.itmill.toolkit.ui.Table.valueChange(Table.java:2299)
	at com.itmill.toolkit.data.util.IndexedContainer.firePropertyValueChange(IndexedContainer.java:923)
	at com.itmill.toolkit.data.util.IndexedContainer.access$1100(IndexedContainer.java:59)
	at com.itmill.toolkit.data.util.IndexedContainer$IndexedContainerProperty.setValue(IndexedContainer.java:1285)
	at com.itmill.toolkit.ui.Table.addItem(Table.java:1528)
	at (here is my class at the line that calls addItem() in the table)

I read on the forum where I could use the application instance to synchronize, so my code looks like this:


            Integer id = new Integer(job.getJobId());
            synchronized (getApplication())
            {
                if (table.containsId(id))
                    table.removeItem(id);
                table.addItem(new Object[] { name, runTime, jobData }, id);
            }

Should I do anything else to stop this exception? The application appears to work ok, except that it misses that one update (every once in a while).

(bump)

Im confused by the

[quote]
web application instance has been stopped already
[/quote] message from the web container - it appears that your application stops (or context was undeployed) for some reason, so this could be even not an toolkit sync problem but another one.

Could you check that nothing accidently kills the server/thread ?

Thanks, I don’t understand that message either.

I am converting to itmill from JSPs , and they have worked (and continue to work) for long periods on the same server, so I know that the server itself is not being killed.

Regarding a possibly killed thread: I’m using Tomcat (embedded in JBoss) as my server, and I’ve not written anything specifically to kill threads. Are you suggesting that there’s possibly a timeout (or something) on the server side that’s causing a thread containing the itmill application/context to die?

Actually, webapp context should terminate on any timeout and work until it manually undeployed, server stopped or some fatal error occurs in a web container or app.

When this exception happens, is the web context still alive or it restarts , e.g. if you refresh a page/itmill application - is the current session with all it states alive or a new session is opened ?

I just tried it, and it appears that the context is alive, I did a page refresh and confirmed that several state variables (member variables in my subclass of Application) retained their values without having to reload from the back-end database.

Since the timing seems rather random, I don’t really think it’s a timeout. Sometimes it happens within a minute or two of starting my server and connecting the client, sometimes it takes hours.

First a little disclaimer: Never seen this before, so I’m basically just thinking out loud here… :slight_smile:

Your thread tries to load a class that is available in a web application that is not anymore available (has been restarted/undeployed)… or at least that what the update threads class loader thinks.

The class probably is available, but it has been loaded by a WebappClassLoader that has been already invalidated (undeployment/redeployment).

This can happen, when if the thread lives longer than a web application is deployed, but you say that the application is alive all the time.

So, I’m thinking of the situation where the update thread uses
different
WebAppClassLoader than the itmill application uses. Are there several itmill-toolkit-x.x.x.jar files available to the web server (in different web app contexts or in common lib) that may have been loaded concurrently? Is the thread started within the same webapp context than the itmill application?

Anyway, I don’t think that there is much that you can do in a itmill application to avoid this. If you have multiple classloaders present you might try to use Thread.setContextClassLoader to force some specific classloader to be used.