• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Java Program that uses ThreadLocal doesn't terminate  RSS feed

 
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a simple Java program that call the below method which uses the ThreadLocal class. When i am running this java program in eclipse it doesn't terminate. When i debug the application it is going to the Thread class and simple hanging there. Why my program doesn't terminate. Please advice.

------------------------------------------------------------------------------------------------------------------
private static final ThreadLocal<Transaction> threadTransaction = new ThreadLocal<Transaction>();

method{
Transaction tx = (Transaction) threadTransaction.get();

if (tx == null) {
tx = getSession(true).beginTransaction();
threadTransaction.set(tx);
}
}
--------------------------------------------------------------------------------------------------------------------


Thanks
Aadil
 
Ranch Hand
Posts: 417
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aadil Shaik wrote:Hello,

I have a simple Java program that call the below method which uses the ThreadLocal class. When i am running this java program in eclipse it doesn't terminate. When i debug the application it is going to the Thread class and simple hanging there. Why my program doesn't terminate. Please advice.

------------------------------------------------------------------------------------------------------------------
private static final ThreadLocal<Transaction> threadTransaction = new ThreadLocal<Transaction>();

method{
Transaction tx = (Transaction) threadTransaction.get();

if (tx == null) {
tx = getSession(true).beginTransaction();
threadTransaction.set(tx);
}
}
--------------------------------------------------------------------------------------------------------------------


Thanks
Aadil



My guess is that it is not related to ThreadLocal.

For example, in order to have a program that uses hibernate SessionFactory terminate, you need to close the SessionFactory for the program to terminate.

It could be your connection pool also or anything that forks a background Thread that keeps your program running.




 
Aadil Shaik
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A.J. Côté wrote: . . .



closing the session factory terminates the program. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!