Thanks for pointing that out. I usually use JTA-enabled datasources so I don't muck around with UserTransaction directly that much.
Derek On Wed, Sep 10, 2008 at 2:23 PM, Martin Ellis <[EMAIL PROTECTED]> wrote: > > On Wed, Sep 10, 2008 at 4:27 PM, Kris Nuttycombe > <[EMAIL PROTECTED]> wrote: > > The only question I have is thread safety - it doesn't seem > > like I should really be using a variable on the singleton to store the > > transaction; should I instead be creating a separate RequestVar to > > hold it? > > It is thread safe to use a singleton - in fact, it's what Sun do in > the code that accompanies the Java EE Tutorial... > > web/books/src/main/java/com/sun/books/listeners/ContextListener.java: > > public final class ContextListener implements ServletContextListener { > @PersistenceUnit > private EntityManagerFactory emf; > private ServletContext context = null; > @Resource > private UserTransaction utx; > > public void contextInitialized(ServletContextEvent event) { > context = event.getServletContext(); > > try { > context.setAttribute("emf", emf); > Globals.UTX = utx; > > > ... where Globals is defined as: > > public class Globals { > public static UserTransaction UTX; > } > > > Hence, using val instead of def should be fine. > > The begin() and commit() javadoc on UserTransaction: > "Create a new transaction and associate it with the current thread." > "Complete the transaction associated with the current thread. When > this method completes, the thread is no longer associated with a > transaction." > > The transaction is associated with the thread that called begin() > 'internally', so there's no need to associate it with a thread > manually. > > See also: > http://java.sun.com/javaee/5/docs/tutorial/doc/bnafo.html > > Martin > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---