Search code examples
netbeans-platform

How do you start custom non-UI threads on a Netbeans platform application?


Q: How do you start custom non-UI threads on a Netbeans platform application?

This was never a problem for me with swing applications since I had a main class to work with.

Here is how I used to do it.

//Execute main method.
public static void main(String args[]) 
{
    //Start thread 1.
    (new Thread(new ThreadClass1())).start();
    //Start thread 2.
    (new Thread(new ThreadClass2())).start();
    //Start thread 3.
    (new Thread(new ThreadClass3())).start();
}

I do prefer the net-beans platform but it manages much of these start up functions differently than what I am used to. Thankyou in advance.


Solution

  • I found the answer to my question and I thought to write it out.

    I have a class called StartupClass.java and you need to declare it in the module manifest as:

    OpenIDE-Module-Install: parentFolder/StartupClass.class
    

    Here is the code:

    import org.openide.modules.ModuleInstall;
    
    public class StartupClass extends ModuleInstall 
    {
        //This method is executed at startup.
        @Override
        public void restored()
        {
            //Start thread 1.
            (new Thread(new ThreadClass1())).start();
            //Start thread 2.
            (new Thread(new ThreadClass2())).start();
            //Start thread 3.
            (new Thread(new ThreadClass3())).start();
        }
    }
    

    Hope this helps if anyone needs it.