java ee - Why @PostConstruct called twice on @Singleton -


i running simple .war file under glassfish 4.0-b87 created in eclipse kepler m6 using m2e simple project dynamic web module facet added, using oracle java 7 jdk/jvm.

there single class expect post_construct method called once. called twice, first when app deployed, , 1 more time on first , first http request.

here class (the log output follows):

package com.example.main;  import javax.annotation.postconstruct; import javax.annotation.predestroy; import javax.ejb.localbean; import javax.ejb.postactivate; import javax.ejb.prepassivate; import javax.ejb.singleton; import javax.ejb.startup; import javax.enterprise.inject.spi.passivationcapable; import javax.ws.rs.applicationpath; import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.core.application;  @singleton @startup @localbean @applicationpath("/rest") @path("/life") public class life extends application implements passivationcapable {    @postconstruct   public void post_construct () {     system.out.println("hello world!");   }    @predestroy   public void pre_destroy () {     system.out.println("so long , fish!");   }    @prepassivate   public void pre_passivate () {     system.out.println("taking break");   }    @postactivate   public void post_activate () {     system.out.println("back break");   }    @override   public string getid () {     return "life";   }    @get   public string greet () {     return "hi";   } } 

the log output follows dashed line separating part before first http call , part after http call:

[2013-05-09t19:42:26.660-1000] [glassfish 4.0] [info] [ncls-deployment-00027] [javax.enterprise.system.tools.deployment.autodeploy] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546660] [levelvalue: 800] [[   selecting file /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/singleton.war autodeployment]]  [2013-05-09t19:42:26.692-1000] [glassfish 4.0] [info] [] [javax.enterprise.system.tools.deployment.common] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546692] [levelvalue: 800] [[   visiting unvisited references]]  [2013-05-09t19:42:26.702-1000] [glassfish 4.0] [info] [] [javax.enterprise.system.tools.deployment.common] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546702] [levelvalue: 800] [[   visiting unvisited references]]  [2013-05-09t19:42:26.706-1000] [glassfish 4.0] [info] [] [javax.enterprise.system.tools.deployment.common] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546706] [levelvalue: 800] [[   visiting unvisited references]]  [2013-05-09t19:42:26.709-1000] [glassfish 4.0] [info] [] [javax.enterprise.system.tools.deployment.common] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546709] [levelvalue: 800] [[   visiting unvisited references]]  [2013-05-09t19:42:26.749-1000] [glassfish 4.0] [info] [ejb.portable_jndi_names] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546749] [levelvalue: 800] [[   ejb5181:portable jndi names ejb life: [java:global/singleton/life, java:global/singleton/life!com.example.main.life]]]  [2013-05-09t19:42:26.959-1000] [glassfish 4.0] [warning] [] [org.jboss.weld.bootstrap] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546959] [levelvalue: 900] [[   weld-001473 javax.enterprise.inject.spi.bean implementation org.glassfish.jms.injection.jmscdiextension$localbean@cbcbf4a declared normal scope not implement javax.enterprise.inject.spi.passivationcapable. won't possible inject bean bean passivating scope (@sessionscoped, @conversationscoped). can fixed assigning bean implementation unique id implementing passivationcapable interface.]]  [2013-05-09t19:42:26.970-1000] [glassfish 4.0] [info] [] [] [tid: _threadid=59 _threadname=thread-3] [timemillis: 1368164546970] [levelvalue: 800] [[   hello world!]]  [2013-05-09t19:42:26.982-1000] [glassfish 4.0] [info] [] [org.glassfish.jersey.servlet.init.jerseyservletcontainerinitializer] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546982] [levelvalue: 800] [[   registering jersey servlet application, named com.example.main.life, @ servlet mapping /rest/*, application class of same name.]]  [2013-05-09t19:42:26.988-1000] [glassfish 4.0] [info] [as-web-glue-00172] [javax.enterprise.web] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164546988] [levelvalue: 800] [[   loading application [singleton] @ [/singleton]]]  [2013-05-09t19:42:27.003-1000] [glassfish 4.0] [info] [] [javax.enterprise.system.core] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164547003] [levelvalue: 800] [[   singleton deployed in 332 milliseconds.]]  [2013-05-09t19:42:27.006-1000] [glassfish 4.0] [info] [ncls-deployment-00035] [javax.enterprise.system.tools.deployment.autodeploy] [tid: _threadid=59 _threadname=autodeployer] [timemillis: 1368164547006] [levelvalue: 800] [[   [autodeploy] autodeployed : /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/singleton.war.]] 

------------------------------after first http call------------------------------

[2013-05-09t19:42:44.940-1000] [glassfish 4.0] [info] [] [] [tid: _threadid=21 _threadname=thread-3] [timemillis: 1368164564940] [levelvalue: 800] [[   hello world!]]  [2013-05-09t19:42:44.940-1000] [glassfish 4.0] [info] [] [org.glassfish.jersey.server.applicationhandler] [tid: _threadid=21 _threadname=http-listener-1(4)] [timemillis: 1368164564940] [levelvalue: 800] [[   initiating jersey application, version jersey: 2.0-rc2 2013-04-23 12:04:25...]]  [2013-05-09t19:42:44.956-1000] [glassfish 4.0] [info] [] [org.glassfish.jersey.gf.ejb.ejbcomponentprovider] [tid: _threadid=21 _threadname=http-listener-1(4)] [timemillis: 1368164564956] [levelvalue: 800] [[   jersey ejb interceptor bound. jax-rs ejb integration support enabled.]] 

<update> glassfish bug https://java.net/jira/browse/glassfish-20505 </update>

it seems @singleton, , @applicationpath + extends application not playing nice each other. perhaps behavior correct in jax-rs needs instantiate application class once, , ejb needs instantiate @singleton once, until points relevant part of standards best consider bug. jersey should recognize @singleton annotation , extends application class rather creating own.

the workaround probable jersey bug not use same class both @singleton , jersey application class.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -