This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server Trouble or ORM

 
Rudradutt Joshi
Ranch Hand
Posts: 45
Fedora Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Servlets
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
Fedora Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic