Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

variables in EJB  RSS feed

 
Tmmet Johnson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I use statelss session beans.Also, I have singleton class which contains many getter methods.

My question are
1. Is it safe to have member variables in stateless beans?
If not, could you please say me the reason.

2. I have a Singleton class which has many getter methods.
In Stateless Session bean ,can I have like below Objects
from singleton as member variable).

public class UserBean implements javax.ejb.SessionBean{

private MysqlDataAccessObject obj = Singleton.getInstance
().getMySqlDataAccessObject();

}


Thanks in advance,
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tmmet Johnson:
Hi,
I use statelss session beans.Also, I have singleton class which contains many getter methods.

My question are
1. Is it safe to have member variables in stateless beans?
If not, could you please say me the reason.

2. I have a Singleton class which has many getter methods.
In Stateless Session bean ,can I have like below Objects
from singleton as member variable).

public class UserBean implements javax.ejb.SessionBean{

private MysqlDataAccessObject obj = Singleton.getInstance
().getMySqlDataAccessObject();

}


Thanks in advance,


It is definitely possible to have instance variables in a SLSB. Whether it thread - safe or not depends on the implementation. Is your singelton thread -safe ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!