3 Replies Latest reply on Nov 8, 2010 6:49 AM by Wolf-Dieter Fink

    Transaction taking long time to execute

    Mayur B Newbie

      Hi, I am using Jboss 5.1.0 GA, EJB 3.0 , MySQL 5.x 

      My application is running on a Linux server.

      In my  java program(client), multiple threads are trying to access the entity bean "LiveSubscriber" using following funtion:

       

      //=====================================Stateless Session Bean==============================

      package com.teshwa.bingogame.clubbeans;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.util.ArrayList;
      import java.util.Calendar;
      import java.util.Date;
      import java.util.Enumeration;
      import java.util.List;
      import java.util.Random;
      import java.util.Vector;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.NoResultException;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceContext;
      import javax.persistence.Query;
      import javax.persistence.RollbackException;
      import com.teshwa.bingo.clubs.ClubBLO;
      import com.teshwa.bingo.clubs.ClubDAO;
      import com.teshwa.bingo.clubs.ClubManager;
      import com.teshwa.bingo.game.Game;
      import com.teshwa.bingo.game.ticket.Ticket;
      import com.teshwa.bingogame.GameRule;
      import com.teshwa.bingogame.LiveClub;
      import com.teshwa.bingogame.LiveGame;
      import com.teshwa.bingogame.LiveSubscriber;
      import com.teshwa.bingogame.jpo.Bingo75_ticket;
      import com.teshwa.bingogame.jpo.Bingo90_ticket;
      import com.teshwa.bingogame.jpo.Bingo_game;
      import com.teshwa.bingogame.jpo.Bingo_game_pattern;
      import com.teshwa.bingogame.jpo.Bingo_game_type;
      import com.teshwa.bingogame.jpo.Bingo_game_type_rule;
      import com.teshwa.bingogame.jpo.Bingo_game_type_rulePK;
      import com.teshwa.bingogame.jpo.Bingo_game_winner;
      import com.teshwa.bingogame.jpo.Club;
      import com.teshwa.bingogame.jpo.Club_schedule_date;
      import com.teshwa.bingogame.jpo.Game_jackpot;
      import com.teshwa.bingogame.jpo.Game_jackpot_transaction;
      import com.teshwa.bingogame.jpo.Game_timetable_detail;
      import com.teshwa.bingogame.jpo.Subscriber;
      import com.teshwa.bingogame.jpo.Subscriber_purchased_ticket;
      @Stateless
      public class GameManagerBean implements GameManagerRemote {
      @PersistenceContext (unitName=ContextMapper.MAPPINGNAME) private EntityManager manager;
      public GameManagerBean(){
      }
      @Override

      package com.clubbeans;

       

      import statements....

       

      @Stateless

      public class GameManagerBean implements GameManagerRemote {

      @PersistenceContext (unitName="gamesproject") private EntityManager manager;

       

      public GameManagerBean(){

      }

      @Override

             public List<LiveSubscriber> getAllSubscribers() {

                      System.out.println("Inside Method");

                       try{

       

            return (List<LiveSubscriber>)manager.createQuery("SELECT lb FROM LiveSubscriber lb").getResultList();

       

                     }catch(NoResultException nr){

                            System.out.println("getting out");

            return null;

                     }

      }// Method ENDS

      }// Class ENDS

      //=========================================================================================

       

      My Problem:  SOMETIMES (5 out of 100 tries, mostly when number of threads acccessing, increases) the control from this method  doesnt return immediately ... it prints the statement "inside method"...but doesnt print the log statement at client side , immediately after this method call. It was printed after 4 to 5 minutes.

       

      My guess is that since lots of threads accessing the LiveSubscriber (live_subscribers table in DB) , sometimes this thread gets locked for longer time and doesnt comeout immediately . If this happens for 1 or 2 minutes , its ok for my application , but it should come out atleast after 2 minutes , otherwise next scheduling gets screwd up.

       

      here is information from my persistence.xml ---->

      persistence-unit name="gamesproject" transaction-type="JTA"

      jta-data-source---->jdbc/ser

      class--->com.LiveSubscriber

      property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"

      property name="hibernate.hbm2ddl.auto" value="create"

       

      I am not using any deployment descripter for session beans. 

       

      Do I need to change default isolation level for Datasource (How?)  or this one perticular method should be bean managed using EntityManger.lock?

      Basically can anybody tell how to prevent this transaction taking so much time?