Robert Strong

Ranch Hand
+ Follow
since Sep 10, 2002
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Robert Strong

hi, I encountered the issue of the limited concurrency in tomcat.

In my code, I use Apache HttpClient to send multiple concurrent requests from the client box to the JSP page on server box. Surprisingly, from the server-side log, I noticed tomcat can only process two requests for the particular JSP page concurrently, the requests after the first two would be processed sequentially.

I guess JSP page would be compiled into the thread-safe servlet, which should be able to be called by multiple threads concurrently. I'm not sure where I can change the configurations?

any help appreciated!
11 years ago

yes, that helps.

So, when the classloader thread start loading the Singleton class, it also kick off static initialization, which is guaranteed to happen before the class is used.
yes, I do use private constructor.

but my question is that if the Singleton class is accessed by multiple threads, is it possible to have a race condition, that in the middle of static initialization, another thread calls getInstance() and thus return null? as no synchronization employed in getInstance() method to ensure timely visibility and atomicity.


I'm a little confused about the role static initialization played in threadsafety of a Singleton class.

a Singleton class like below seems to be working correctly without making the reference variable final.

public class Singleton {
private static Singleton s = new Singleton();

public Static Singleton getInstance() {
return s;

however, I saw lots of singleton examples in Effective Java look like below, with a final keyword
public class Singleton {
private static final Singleton s = new Singleton();

I heard some people say that static initialization use internal synchronization of classloader to ensure no race condition for the reference variable? is it true?
hi, I'm new in multi-threading, I know that to share data among threads, synchronization must be employed.
But in the books, I've seen lots of code like below:

public void read(final Connection con){
executor.submit(new Runnable() {
public void run() {

I think here the Object con is passed from current thread to another thread in the executor pool. But no synchronization is used besides the final modifier, would it still work?


I'm working on a project using Spring2.5 and JBoss, one of my team members created a spring bean class like below:

public class MemberConfig {
static private MemberConfig config;

public static void setConfig(MemberConfig config) {
MemberConfig.config = config;

public static MemberConfig getInstance () {
return config;



and then in ContextLoaderListener.contextInitialized() method this bean is accessed like below:

MemberConfig conf = applicationContext.getBean("memberConfig");
MemberConfig.setConfig(conf); //unsafe publish

I believe the way we access the static variable: MemberConfig.config is not threadsafe, as when MemberConfig.setConfig(conf) is called in ContextLoaderListener.contextInitialized(), no synchronization is employed, it's not a safe publish. So, when we call MemberConfig.getInstance () it might return a stale reference or null.

However my colleague thought since MemberConfig.config is initialized in Spring ContextLoaderListener.contextInitialized(), it would be threadsafe.

I thought my judgement is correct, however I cannot find a way to prove it. when I send multiple concurrent http requests to the JBoss server where the spring application hosted, it seems to be working properly, MemberConfig.getInstance () never returned null, no NullPointerException was thrown.

any ideas about it?

Mike, thank you for your detailed, insightful descriptions.
Mike, thank you for your quick reply.

you said reference "holder" is mutable, other threads might see stale value of holder, but will initialization safety guaranty the most recent writes are visible to other threads?

hi, i'm new in multi-threading, i'm a little confused about safe publish and threadsafe of immutable object.

I know that immutable object is always threadsafe and can always be safely published thanks to initialization safety. does this mean that in the following code, the update() is threadsafe without synchronization?

public Cache {
private ImmutableObject holder;

public update(...) {
holder = new ImmutableObject(...);

any help is appreciated!

I'm using BEA Webloigc8.1 Stateless Session Bean/DAO/Oracle stored proc.
but I'm not quite clear how Transaction Manager work with Resource Manager, like Connection pool.

my understanding is that, in a weblogic transaction, a stateless session bean interact with several DAOs, and for each method of DAO a connection is acquired from connection pool. I've heard that the connection will not return to pool until the transaction commits.

My question is that, does it mean that for a weblogic transaction, multiple connections might be allocated to it? and if multiple connections are allocated, then how many oracle transactions would be started? or multiple connections share the same oracle transaction?

I didn't feel it make sense to start multiple oracle transactions, cause deadlock might be incurred in a single weblogic transaction.

any help appreciated!

I'm using BEA weblogic8.1 to develop J2EE application in a cluster environment, where EJB is clustered.

But occurred, when I call clustered Stateless session bean from a webapp outside of the cluster.

my code is below:

CatalogServiceRemote catalogServiceRemote = (CatalogServiceRemote)Locator.getSessionBean("CatalogService");
//Remote Stub is successfully acquired using ServiceLocator

this.categoryList = (ArrayList)catalogServiceRemote.getTopCategories();
//when a remote method is called, remote exception is thrown

catch(NamingException ne){
catch(RemoteException re){

exception like below:

java.rmi.RemoteException: EJB Exception: ; nested exception is:
javax.ejb.EJBException: nested exception is: javax.naming.ServiceUnavail
ableException [Root exception is]

I'm not sure why it cannot find host:, which is a host where a weblogic instance of the cluster resides. and I can ping successfully.

any help appreciated!
hi, I'm working on a weblogic workshop application, which consists of a Java project, a EJB project and a Web project. everything seems to be working in workshop develop environment.

but when I try to build an EAR and deploy it to a cluster, things go wrong, only the web module is deployed with the EAR. I unwrapped the EAR file, and I found that the application.xml in EAR is wrong, it doesn't include the EJB module. but when I go to check workshop application file, in the directory of 'META-INF', the application.xml does contain the EJB Module.

so, how can this inconsistencies happen? is it a bug of workshop?
hi, I usually used session facade pattern with 1 stateless session bean as a controller interacting with several Entity Bean to realize business logic in usecase.

now, as business logic grows more complex, to promote component reuse, I'd like to add a common service layer between the controller stateless session bean and Entity Beans. Should I use stateless session beans for this kind of common service layer? I'm afraid that a transaction span across multiple stateless session beans would hurt performance?

anyone here could help me out?
hi, I'm trying to use EJB Clustering on Weblogic8.1, I've been told that nothing need to change in order to make Stateless Session Bean using remote interfaces work on Clustered Weblogic8.1 server, cause when the EJB is deployed to the cluster, the clustered stub would be generated. Is this true? I also heard that I need to add a list of idompotent methods in the deployment descriptor to achieve load balance and failover?

anyone here could help me out?

I'm using BEA Weblogic8.1, I'm coding a Stateless Session Bean, used for Signup, there a user's account should be created in both LDAP and Oracle Database. XA JDBC driver used, with <trans-attribute>Required</trans-attribute> specified in ejb-jar.xml.

if that account already exists in database table, the transaction would rollback, but an entry still created in LDAP. so, it seems LDAP operations and database access cannot be grouped into one distributed transaction?

my code is like below:
ht.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
ht.put(Context.PROVIDER_URL, "ldap://tiger:7001");
ht.put(Context.SECURITY_AUTHENTICATION, "simple");
ht.put(Context.SECURITY_PRINCIPAL, "cn=Admin");
ht.put(Context.SECURITY_CREDENTIALS, "xxxxx");
dirCtx = new InitialDirContext(ht);

Attributes attrNew = new BasicAttributes(true);
Attribute oc = new BasicAttribute("objectclass");
Attribute ouSet = new BasicAttribute("ou");


attrNew.put("wlsMemberOf", "cn=bigrez_staffs,ou=groups,ou=myrealm,dc=bigrezdomain");
attrNew.put("sn", staffVO.getName());
attrNew.put("uid", staffVO.getEmail());
attrNew.put("cn", staffVO.getEmail());
String pwd = "test";
attrNew.put("userpassword", pwd.getBytes());

///add new entry
dirCtx.createSubcontext("cn=" + staffVO.getEmail() + ",ou=people,ou=myrealm,dc=bigrezdomain", attrNew);

StaffEntityHomeLocal staffEntityHomeLocal = (StaffEntityHomeLocal)Locator.getHome("StaffEntity");