<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Transaction taking long time to execute
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/bingojava">Mayur B</a> in <i>Performance Tuning</i> - <a href="http://community.jboss.org/message/569947#569947">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi, I am using Jboss 5.1.0 GA, EJB 3.0 , MySQL 5.x  </p><p>My application is running on a Linux server. </p><p>In my  java program(client), multiple threads are trying to access the entity bean "LiveSubscriber" using following funtion:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>//=====================================Stateless Session Bean==============================</p><p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">package com.teshwa.bingogame.clubbeans;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.sql.PreparedStatement;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.sql.ResultSet;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.ArrayList;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Calendar;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Date;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Enumeration;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.List;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Random;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Vector;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.ejb.Stateless;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.EntityManager;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.EntityManagerFactory;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.NoResultException;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.Persistence;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.PersistenceContext;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.Query;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.persistence.RollbackException;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingo.clubs.ClubBLO;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingo.clubs.ClubDAO;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingo.clubs.ClubManager;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingo.game.Game;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingo.game.ticket.Ticket;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.GameRule;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.LiveClub;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.LiveGame;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.LiveSubscriber;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo75_ticket;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo90_ticket;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo_game;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo_game_pattern;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo_game_type;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo_game_type_rule;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo_game_type_rulePK;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Bingo_game_winner;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Club;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Club_schedule_date;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Game_jackpot;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Game_jackpot_transaction;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Game_timetable_detail;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Subscriber;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import com.teshwa.bingogame.jpo.Subscriber_purchased_ticket;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@Stateless</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class GameManagerBean implements GameManagerRemote {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@PersistenceContext (unitName=ContextMapper.MAPPINGNAME) private EntityManager manager;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public GameManagerBean(){</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@Override</div><p>package com.clubbeans;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import statements....</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@Stateless</p><p>public class GameManagerBean implements GameManagerRemote {</p><p><span style="white-space: pre;"> </span>@PersistenceContext (unitName="gamesproject") private EntityManager manager;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="white-space: pre;"> </span> </p><p><span style="white-space: pre;"> </span>public GameManagerBean(){<span style="white-space: pre;"> </span></p><p><span style="white-space: pre;"> </span>}</p><p><span style="white-space: pre;"> </span>@Override</p><p>       public List<LiveSubscriber> getAllSubscribers() {</p><p>                System.out.println("Inside Method");</p><p><span style="white-space: pre;"> </span>                 try{</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;">      </span>return (List<LiveSubscriber>)manager.createQuery("SELECT lb FROM LiveSubscriber lb").getResultList();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>               }catch(NoResultException nr){</p><p>                      System.out.println("getting out"); </p><p><span style="white-space: pre;">      </span>return null;</p><p>               }</p><p><span style="white-space: pre;"> </span>}// Method ENDS</p><p>}// Class ENDS</p><p>//=========================================================================================</p></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>here is information from my persistence.xml ----></p><p>persistence-unit name="gamesproject" transaction-type="JTA"</p><p><p>jta-data-source---->jdbc/ser</p><p>class--->com.LiveSubscriber</p></p><p>property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"</p><p>property name="hibernate.hbm2ddl.auto" value="create"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I am not using any deployment descripter for session beans.  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Do I need to change default isolation level for Datasource (How?)  or this one perticular method should be bean managed using EntityManger.lock?</p><p>Basically can anybody tell how to prevent this transaction taking so much time?</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/569947#569947">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Performance Tuning at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2078">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>