[Resolved] Call MainWindow in a thread


I’m want to call the method MyApp.getProject().getMainWindow().showNotification() in a run() method of a thread but MyApp.getProject() return null. Someone already had this problem? How can I resolved it?



What does your getProject() -method do? I’ll try to guess. It is an implementation of the ThreadLocal-pattern, and you’re trying to get the application instance from another thread. In that case, you have to set the application instance to the threadlocale for that thread manually.

I’m not sure to understand what you say :confused:

I have this in my main application source :

	protected static ThreadLocal<MyApplication> thisApplication = 
               new ThreadLocal<MyApplication>();

        public static void setProject(MyApplication t) {
	public static MyApplication getProject() {
		return thisApplication.get();
        public static void createTaskThread(MyApplication myApplication){
		TaskThread taskThread = new TaskThread(myApplication, MyApplication.DELAY);

and I have a class that extends Thread and I want to do this :

public class TaskThread extends Thread {
       public TaskThread(MyApplication myApplication, int delay) {
               this.myApplication = myApplication; 
	public void run(){

But I can’t, I have a NullPointerException! So can you give me an example?


Try adding this to your TaskThread constructor:


The reason for this is, that the ThreadLocal is, well, local to the thread. So when you try to get the application instance from any other thread than the UI thread (the one that calls transactionlistener methods), it isn’t automatically available for that thread.

I had this and there are no change.

While i’m in the constructor, I can set notification but in the run() I can’t, the getProject method return null.

Try using InheritableThreadLocal instead of ThreadLocal.

Thanks for this tips, I can remove MyApplication from parameters and it’s work but the window is not refresh. I must click on a link, button or other component to see my notification.


To refresh application window from client side, you must use hidden ProgressIdicator control or Refresher control from incubator.

Thanks, It’s work with Refresher.