top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is EJB in Java? What are the different types of EJB?

+3 votes
86 views
What is EJB in Java? What are the different types of EJB?
posted Feb 1, 2015 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Enterprise java bean (EJB) is a server side component which runs on application server or we call container, developed for the purpose of distributed and enterprise level application .container will provide support for system level services like Transaction Management, security which make developer task easy and he can focus on business logic.

Types of EJB:

Entity Bean: it represents an entity which is mapped with database or we can say it makes OR object Relational mapping with Database. Entity bean typically represent table in RDBMS and each instance represent row in the table.
Two types of entity bean:
a) CMP Entity bean: Container managed entity bean its responsibility of container to manage the bean persistence behavior.
b) BMP Entity bean: Programmer manage the bean persistence behavior.

Session bean: Session bean is responsible for developing business logic it makes the client server relationship so session beans exist till there is a session exist between client and server, it doesn’t contain persistent business concept.
Types of session bean
a) Stateless session bean: when there is not need to maintain state of a particular client stateless session bean is used .They alive for short period of time. For example if we are validating the credit card we can use stateless session bean.
b) State full session bean: state full session bean maintain the conversational state of client over the series of method call before the bean instance goes to passive state conversational state is saved to persistence area like Hard disk and again when same client send a request and bean instance come into the active state it will come out from hard disk to main memory.
For Example when we do online banking transaction ,online reservation we use state full session bean

Message Driven Beans: these beans are work as a listener for messaging services like JMS .

answer Feb 12, 2015 by Kali Mishra
Similar Questions
+2 votes
import java.util.ArrayList;
import java.util.List;

public class ThreadB extends Thread {
    private static List<String> list1   = new ArrayList<String>();
    private static List<String> list2   = new ArrayList<String>();
    private static final Object mutex   = new Object();

    public void run() {
        try {
            sleep(2000l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        synchronized (mutex) {
            list1.add("Hello");
            System.out.println("Added for 1   " + list1.size());
            list2.add("Added for 2");
            System.out.println("Added for 2   " + list2.size());
            mutex.notify();
        }
    }

    public static void main(String[] args) {
        ThreadB a1 = new ThreadB();
        ThreadB a2 = new ThreadB();
        a1.start();
        a2.start();
        new ThreadB().m1();    
    }

    private void m1() {         
        synchronized (list1) {
            System.out.println(list1.size());
            System.out.println(list2.size());
            try {
                list1.add("hello");
                System.out.println("m1  :::   " + list1.size());
                sleep(5000l);
                System.out.println("Oh mY God");
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }
}

Output is

0
0
m1  :::   1
Added for 1   2
Added for 2   1
Added for 1   3
Added for 2   2
Oh mY God

After locking list1, how other threads are going to access that list?

...