X

Geertjan's Blog

  • July 10, 2012

@OnStart & @OnStop

Geertjan Wielenga
Product Manager

In applications based on NetBeans Platform 7.2, you'll be able to replace all your ModuleInstall classes with this code:

import org.openide.modules.OnStart;
import org.openide.modules.OnStop;
@OnStart
public final class Installer implements Runnable {
@Override
public void run() {
System.out.println("enable something...");
}
@OnStop
public static final class Down implements Runnable {
@Override
public void run() {
System.out.println("disable something...");
}
}
}

Build the module and the annotations result in named services, thanks to @NamedServiceDefinition:

Aside from no longer needing to register the ModuleInstall class in the manifest, performance of startup will be enhanced, if you use the above approach:

https://netbeans.org/bugzilla/show_bug.cgi?id=200636

Join the discussion

Comments ( 2 )
  • Bertha Truble Saturday, March 15, 2014

    It is unclear to me how to "enable something" across modules. For example, if you used the onStart for a login similarly to what you did here: https://blogs.oracle.com/geertjan/entry/simple_security_mechanism_for_the, but I'm not sure how to make sure the login occurs before the other modules are enabled.


  • Daniel Felix Ferber Friday, August 1, 2014

    I created several @OnStart annotation runnable classes within the same module. Each class implements an independent initialization code. I observed that several threads are created to run @OnStart annotated runnables in parallel, which may cause race conditions.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services