Vaadin UI hangs upon any unhandled runtime exception

Guys,

I am a newbie on vaadin. Please help me what this problem is all about.

I am facing a strange issue in Vaadin. When any runtime exception occurs which is not handled by my application class, hangs the client UI and eventually the connection times-out. After that, the application becomes unresponsive to all users and in any other browser also(not a cache issue). Ideally, it should show the stack trace in component error UI part. The application is deployed on Sun Solaris, using Oracle iplanet server 7 and Vaadin 6.4.0 version jar.
In case no exception occurs, then application use to work fine for all the users. Also, the same application is working fine on local Windows 7 system.

Note: Onething I noticed that, the runtime exception was getting logged in application servers errror log and not on the UI in which case it should have been catch by default vaadin terminal’s ErrorListener.

In the application class I am using the Vaadin threadlocal pattern using HttpServletRequestListener. Below is the code snippet. Please let me know if it has anything to do with ThreadLocal instance.

//skeleton code
public class VaadinApplication extends Application
implements HttpServletRequestListener {

private static ThreadLocal currentApplication =
new ThreadLocal ();

public void init() {

	setInstance(this);
    buildMainLayout();//app logic here
}

@Override
public void close() {

    super.close();
    stopRefresherThread();
    currentApplication.set ( null ); // i guess i need to remove this, but I think this should not craete any problem ???
    currentApplication.remove ();
    setUser(null);
}

@Override
public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
	WorkflowServiceApplication.setInstance(this);     
}      

@Override
public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
  currentApplication.remove();     
} 

// Set the current application instance
public static void setInstance(WorkflowServiceApplication application) {
if (getInstance() == null) {
currentApplication.set(application);
}
}

public static WorkflowServiceApplication getInstance() {
	return currentApplication.get();
}

}

Hi,

I did not come up with any obvious cause just by reading through the provided code, but this caught my eye:

stopRefresherThread();

Could you describe a little what you are doing, especially with threads?

Also, could you provide a stacktrace for an exception that causes the behavior you describe?

Best Regards,
Marc

Hi,

Please find below the code snippet which uses the Refresher add-on in [quote]
stopRefresherThread()
[/quote]


//skeleton code
public class VaadinApplication extends Application implements
		HttpServletRequestListener {

	private static ThreadLocal<VaadinApplication> currentApplication = new ThreadLocal<VaadinApplication>();

	// TODO: to check if ThreadLocal can be removed for Refresher component, as
	// currently not sure in what case the Refresher's internal thread will be
	// killed.
	// For double check, I have used ThreadLocal and explicitly stopping
	// refresher thread on every request
	private ThreadLocal<Refresher> refreshers = new ThreadLocal<Refresher>();

	public void init() {

		setInstance(this);
		buildMainLayout();// app logic here
	}

	public void buildMainLayout() {

		// initializing the window and its component......

		// based on URI fragment, intializing a component which uses Refresher
		// add-on
		initializeRefresherThread();
		customComponent.addComponent(refresher);
		// else
		// try to stop the refresher even if the previous page that was opened
		// didn't uses the Refresher add-on
		stopRefresherThread();
	}

	@Override
	public void close() {

		super.close();
		stopRefresherThread();
		currentApplication.set(null); // i guess i need to remove this, but I
										// think this should not craete any
										// problem ???
		currentApplication.remove();
		setUser(null);
	}

	@Override
	public void onRequestStart(HttpServletRequest request,
			HttpServletResponse response) {
		WorkflowServiceApplication.setInstance(this);
	}

	@Override
	public void onRequestEnd(HttpServletRequest request,
			HttpServletResponse response) {
		currentApplication.remove();
	}

	// Set the current application instance
	public static void setInstance(WorkflowServiceApplication application) {
		if (getInstance() == null) {
			currentApplication.set(application);
		}
	}

	public static WorkflowServiceApplication getInstance() {
		return currentApplication.get();
	}

	private void initializeRefresherThread() {

		stopRefresherThread();

		refresher = new Refresher();
		refresher.addListener(new RefreshListener() {

			private static final long serialVersionUID = -8765221895426102605L;

			@Override
			public void refresh(final Refresher source) {

				// refreshing values in some component

			}
		});

		refresher.setEnabled(true);
		refresher.setRefreshInterval(SLEEP_TIME_IN_MILLIS);
		refreshers.set(refresher);
	}

	private void stopRefresherThread() {
		Refresher refresherThread = refreshers.get();

		if (refresherThread != null && refresherThread.isEnabled()) {

			refresherThread.setEnabled(false);
			refresherThread.setRefreshInterval(0);

			refreshers.set(null);
			refreshers.remove();
		}
	}

}

Regards
Pulkit

Hi,

Do you have the stracktrace for the exception also?

Best Regards,
Marc

Marc,

Exception is gone but still the UI hangs. is it anything related to threadlocal for refresher add-on???

Hi,

AFAIK Refresher does not need ThreadLocal for anything - maybe you should try to get it working w/o ThreadLocal first so that concepts don’t get mixed up?

Anyway, I’m not sure what you mean by “the UI hangs”? Stops refreshing, or something worse?

Refresher does AFAIK not start any Thread - it is a polling component. What you should do is 1) add the component once to your main layout (during init()) and 2) keep it there (unless you want to stop polling - then you’ll want to disable it).

You might want to read about sessions, users, and application initialization in the book as well (especially if you come from a swing/awt -type background, where the UI is threaded in quite a different way).

Best Regards,
Marc