javaee / ejb-spec

See javax.ejb project for API. Contains legacy issues only.
https://github.com/javaee/javax.ejb
6 stars 1 forks source link

clarify ManagedExecutorService task execution allowance in @PostConstruct method for @Startup Singleton Session Bean #133

Open amykang2020 opened 7 years ago

amykang2020 commented 7 years ago

From @glassfishrobot on June 12, 2014 1:22

I'm attempting to schedule a task from inside a singleton bean which is initialised at startup:

@Singleton
@Startup
public class StartupSingleton {
      @Resource
      ManagedExecutorService executorService;

      @PostConstruct
      public void init() {
            System.out.println("init");
            Future<?> future = executorService.submit(new Runnable() {
  public void run() {
        System.out.println("run");
  }
            });

            try {
  Thread.sleep(1000);
  if(future.isDone()) {
        future.get();
        System.out.println("ok");
  } else {
        System.out.println("not run");
  }
            } catch (Exception e) {
  e.printStackTrace();
            }
      }
}

I then get the following in the logs:

2014-06-10T15:45:07.497+0930|Info: init
2014-06-10T15:45:08.499+0930|Severe: java.util.concurrent.ExecutionException: javax.enterprise.concurrent.AbortedException: Module glassfish-executor-test is disabled
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:188)
      at foo.StartupSingleton.init(StartupSingleton.java:33)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.BeanCallbackInterceptor.intercept(InterceptorManager.java:1035)
      at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
      at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:205)
      at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)
      at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:986)
      at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
      at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:205)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.init(SystemInterceptorProxy.java:125)
      at sun.reflect.GeneratedMethodAccessor130.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:986)
      at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:412)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:375)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:1949)
      at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:475)
      at com.sun.ejb.containers.AbstractSingletonContainer.access$000(AbstractSingletonContainer.java:81)
      at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:654)
      at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:396)
      at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:219)
      at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:180)
      at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:158)
      at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:166)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
      at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
      at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
      at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:356)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
      at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
      at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
      at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
      at java.lang.Thread.run(Thread.java:744)
Caused by: javax.enterprise.concurrent.AbortedException: Module glassfish-executor-test is disabled
      at org.glassfish.enterprise.concurrent.internal.ManagedFutureTask.run(ManagedFutureTask.java:146)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)

And the submitted task is not run. (glassfish-executor-test is just the name of the standalone test case that I created).

Surely either the executor service should be initialized and available by the time tt>@PostConstruct</tt stuff is executed, or it should queue submitted tasks and execute them once the application is started.

This is just using the default managed executor service in a default domain.xml file.

Environment

Glassfish 4.0, Java 7, currently testing on Windows 7

Affected Versions

[4.0]

Copied from original issue: javaee/glassfish#21087

amykang2020 commented 7 years ago

From @glassfishrobot on June 23, 2014 15:14

kingsob said: I am seeing the same thing. Is this a bug? How else would I add a task to the executor on ejb start up?

amykang2020 commented 7 years ago

From @glassfishrobot on July 14, 2014 20:46

mreichman said: Also seeing the same in 4.0.1b8, from an @Asynchronous method called from a @PostConstruct.

Was able to work around it by throwing a Thread.sleep in my @Asynchronous method, but that is certainly not a workable solution.

amykang2020 commented 7 years ago

From @glassfishrobot on December 17, 2014 20:17

afcarv said: Got the same issue. Are you using module/application versioning?

Cause appears to be some mix-up at "org.glassfish.concurrent.runtime.ContextSetupProviderImpl"; method "isApplicationEnabled" checks to see if the current context application is enabled, but I think the app name contains only the base name (e.g. "my-application") while the app list contains the full name (e.g. "my-application:1.0.0"). So no match is found.

I was able to work around by deploying the app without the version but the obvious consequence is losing the versioning feature. Not sure if there's a better way.

amykang2020 commented 7 years ago

From @glassfishrobot on April 28, 2015 10:26

jiggster said: You can configure the deployment order of the ManagedExecutorService resource. Set it to some low value (e.g. 0, by default it's 100), restart the server and check if that helped.

amykang2020 commented 7 years ago

From @glassfishrobot on May 1, 2015 18:53

payara_steve said: This is a related issue with the same cause https://java.net/jira/browse/GLASSFISH-21216

amykang2020 commented 7 years ago

From @glassfishrobot on June 12, 2014 1:22

Was assigned to srini.gf

amykang2020 commented 7 years ago

From @glassfishrobot on April 21, 2017 8:29

This issue was imported from java.net JIRA GLASSFISH-21087

amykang2020 commented 7 years ago

From @glassfishrobot on June 12, 2014 1:22

Reported by tomdcc

amykang2020 commented 7 years ago

This behavior is confirmed with latest GlassFish5 build. However as commented in #21216, the EJB spec for Singleton Session Bean lists explicitly the operations that PostConstruct can perform, so at most this is in a spec "gray" area that needs spec clarification