Tuesday, March 27, 2007

Comparing Stateless and Stateful Session Beans

Upon startup, WebLogic Server automatically creates and populates the free pool with the quantity of instances you specify in the bean's initial-beans-in-free-pool deployment element in the weblogic-ejb-jar.xml file. By default, initial-beans-in-free-pool is set to 0.

If you configure a pool, WebLogic Server will service method calls with an EJB instance from the free pool, if one is available. The EJB remains active for the duration of the client's method call. After the method completes, the EJB instance is returned to the free pool. Because WebLogic Server unbinds stateless session beans from clients after each method call, the actual bean class instance that a client uses may be different from invocation to invocation.

If all instances of an EJB class are active and max-beans-in-free-pool has been reached, new clients requesting the EJB class will be blocked until an active EJB completes a method call. If the transaction times out (or, for non-transactional calls, if five minutes elapse), WebLogic Server throws a RemoteException for a remote client or an EJBException for a local client.

Note: The maximum size of the free pool is limited by the value of the max-beans-in-free-pool element, available memory, or the number of execute threads.

When an application requests a bean instance from the free pool, there are three possible outcomes:

  • An instance is available in the pool. WebLogic Server makes that instance available and your application proceeds with processing.
  • No instance is available in the pool, but the number of instances in use is less then max-beans-in-free-pool. WebLogic Server allocates a new bean instance and gives it to you.
  • No instances are available in the pool and the number of instances in use is already max-beans-in-free-pool. You application must wait until either your transaction times out or a bean instance that already exists in the pool becomes available.
bea docs

Thursday, March 22, 2007

Threads in Java

Synchronization:
Locking is about coordinating the activities of two or more threads, so they can work together and not collide in their use of the same address space. Synchronization makes sure only one thread at a time can perform certain activities that manupulate an object.

In Java
Every Class has a lock
Every instance has a lock.

To synchronize a method:
synchronized void say () {/*do sth*/ }
Because say() is an instance method, a thread has to acquire the lock on the particular instance before it can invoke the say() method.
If say() were a class (static) method instead of an instance method, we could still mark it as synchronized. But in this case as there is no instance object involved, the lock would be on the class object itself