From the course: Java EE 7: Enterprise JavaBeans (EJB)

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Singleton session bean

Singleton session bean

From the course: Java EE 7: Enterprise JavaBeans (EJB)

Start my 1-month free trial

Singleton session bean

- Like mentioned before, a singleton is often used for application-wide code that needs to be initialized and run once. In this case, we'll create a session bean to track how many sessions are currently running. So let's go ahead and create one and look at some code. So the first thing you want to do is scroll all the way down to the web module because we're not going to create this session manager inside of the VinylApp-ejb. We're going to create it inside of our web module so right click on the web module, select new, click on other and then in the categories you want to select Enterprise JavaBeans so we can select session bean and then click next. And for this guy, what we're going to do is call this guy session manager and then in the packages, we're going to type ejb and you want to make sure you select singleton as the type and click finish. All right, so the first thing we're going to do is initialize a few things so we're going to initialize the web listener so we can actually…

Contents