aspose file tools*
The moose likes Servlets and the fly likes Server Trouble or ORM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Server Trouble or ORM " Watch "Server Trouble or ORM " New topic
Author

Server Trouble or ORM

Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

Hello there,
Thanks for your time,I am not sure about the problem's domain so I am posting it here.
I have a servlet which listens at 1234 (Thread) port, but when I start the server it invokes the servlet twice, hence it was binding exception. I solved it by make thread to sleep for a while.
But now as I am doing some ORM with hibernate i am submitting a form at a servlet, in order which invokes my action class..
Here below it is...
servlet


Action Class



now as i said it collapses with error
DynamicFenceDataAction.SaveOrUpdate(75) | Transection not Commited, session not closed
DynamicFenceDataAction.SaveOrUpdate(75) | Transection not Commited, session not closed
DynamicFenceDataAction.SaveOrUpdate(77) | Transection Commited, session not closed
DynamicFenceDataAction.SaveOrUpdate(77) | Transection Commited, session not closed
org.hibernate.SessionException: Session was already closed

So here also it is invoked twice, and that may be is the reason for no existence of session.
Please help, and do tell me if more trace is required.

Agian Thanks in advance
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I would suggest not using a Servlet for listening to the port directly. It is not what Servlets are designed for. since the Server controls the Servlet life cycle and there is no guarantee about when they get created and destroyed, and how many may be created and maintained, they don't do anything more than serving and controlling web content very well.

Instead, try using a a ServletContextListener, which has a servletInitialized method that gets called when the web application is started and would be used to start listening to the port, and a contectDestroyed method called when the application ends, which can be used to close the port. You are guaranteed to have just one instance created, and it will live the length of the application. I much better choice for what you want to do.

Steve
[ December 07, 2008: Message edited by: Steve Luke ]

Steve
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Moving to Servlets


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
In cases of "servlet invoked twice" I always suspect the deployment descriptor. What is your web.xml entry for this servlet?

Bill
Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

In cases of "servlet invoked twice" I always suspect the deployment descriptor. What is your web.xml entry for this servlet?

Bill
It is

I think it is alright, may be URL is of no use.

And steve I had tried with the ServletContextListener also,
but if here also I do not make thread sleep for a while it throws error
otherwise at least it is not telling me that it had initialized twice (something better). so suggest me your opinion.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server Trouble or ORM