users@glassfish.java.net

singleton lifecycle webservice

From: <glassfish_at_javadesktop.org>
Date: Thu, 26 Aug 2010 07:19:18 PDT

Hi,

I have a simple webservice created with Netbeans 6.5 and deployed into 2 glassfish servers V2.1 and V3. The ws has a basic method GetInstanceID that I call 3 times from a client. I always though that web services were singleton by default.

On the [b]glassfish V2.1[/b] server the ws is working as expected, with a singleton lifecycle:
- Only one instance is created.
- Only one execution of constructor method.
- Only one execution of postconstructor method.
- Only one execution of predestroy method when ws is undeployed.

[u]Client log[/u]
InstanceID = -4747957096764272596
InstanceID = -4747957096764272596
InstanceID = -4747957096764272596

[u]Server log[/u]
26/08/2010 13:08:15:146 ***** first.test.FirstWS (m_instanceID=-4747957096764272596): Executing Constructor ThreadID=68 ThreadName=httpSSLWorkerThread-8080-0
26/08/2010 13:08:15:161 ***** first.test.FirstWS (m_instanceID=-4747957096764272596): Executing PostConstruct ThreadID=68 ThreadName=httpSSLWorkerThread-8080-0
26/08/2010 13:08:15:364 ***** first.test.FirstWS (m_instanceID=-4747957096764272596): Executing GetInstanceID ThreadID=69 ThreadName=httpSSLWorkerThread-8080-1
26/08/2010 13:08:15:380 ***** first.test.FirstWS (m_instanceID=-4747957096764272596): Executing GetInstanceID ThreadID=69 ThreadName=httpSSLWorkerThread-8080-1
26/08/2010 13:08:15:396 ***** first.test.FirstWS (m_instanceID=-4747957096764272596): Executing GetInstanceID ThreadID=69 ThreadName=httpSSLWorkerThread-8080-1
26/08/2010 13:08:38:849 ***** first.test.FirstWS (m_instanceID=-4747957096764272596): Executing PreDestroy ThreadID=626 ThreadName=Thread-540

But on the [b]glassfish V3[/b] server the ws isn't working as expected, because a new instance of the ws is created for EVERY call to the GetInstanceID:
- One instance is created [u]for every call[/u].
- One execution of constructor method [u]for every call[/u].
- Two (!?!?!) executions of postconstructor method [u]for every call[/u].
- The predestroy method [u]isn't[/u] called when ws is undeployed.

[u]Client log[/u]
InstanceId = 7754248300017958713
InstanceId = -1714184485890589231
InstanceId = -4156829683887899017

[u]Server log[/u]
INFO: 26/08/2010 15:16:11:429 ***** first.test.FirstWS (m_instanceID=7754248300017958713): Executing Constructor ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:11:429 ***** first.test.FirstWS (m_instanceID=7754248300017958713): Executing PostConstruct ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:11:429 ***** first.test.FirstWS (m_instanceID=7754248300017958713): Executing PostConstruct ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:12:429 ***** first.test.FirstWS (m_instanceID=7754248300017958713): Executing GetInstanceID ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:12:460 ***** first.test.FirstWS (m_instanceID=-1714184485890589231): Executing Constructor ThreadID=102 ThreadName=http-thread-pool-8080-(1)
INFO: 26/08/2010 15:16:13:429 ***** first.test.FirstWS (m_instanceID=-1714184485890589231): Executing PostConstruct ThreadID=102 ThreadName=http-thread-pool-8080-(1)
INFO: 26/08/2010 15:16:13:429 ***** first.test.FirstWS (m_instanceID=-1714184485890589231): Executing PostConstruct ThreadID=102 ThreadName=http-thread-pool-8080-(1)
INFO: 26/08/2010 15:16:14:429 ***** first.test.FirstWS (m_instanceID=-1714184485890589231): Executing GetInstanceID ThreadID=102 ThreadName=http-thread-pool-8080-(1)
INFO: 26/08/2010 15:16:14:445 ***** first.test.FirstWS (m_instanceID=-4156829683887899017): Executing Constructor ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:15:429 ***** first.test.FirstWS (m_instanceID=-4156829683887899017): Executing PostConstruct ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:15:429 ***** first.test.FirstWS (m_instanceID=-4156829683887899017): Executing PostConstruct ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: 26/08/2010 15:16:15:429 ***** first.test.FirstWS (m_instanceID=-4156829683887899017): Executing GetInstanceID ThreadID=103 ThreadName=http-thread-pool-8080-(2)
INFO: Closing Metro monitoring root: amx:pp=/mon/server-mon[server],type=WSEndpoint,name=/FirstWebApplication-FirstWSService-FirstWSPort

So, why this behaviour on glassfish V3? How could I have a singleton web service on glassfish V3? Any help?

Thanks.
[Message sent by forum member 'emoya']

http://forums.java.net/jive/thread.jspa?messageID=481077