title: solve error : log already in use with atomikos with multiple instances
body: <p>I am facing an issue only on live server with atomikos, on my local server it works perfectly.</p>
  
  <p>the issue i am facng on the server is</p>
  
  <p>Error in init(): Log already in use?</p>
  
  <p>complete exception stack trace </p>
  
  <pre><code>java.lang.RuntimeException: Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.createDefault(UserTransactionServiceImp.java:205)
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:265)
      at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:405)
      at com.atomikos.icatch.jta.UserTransactionImp.checkSetup(UserTransactionImp.java:100)
      at com.atomikos.icatch.jta.UserTransactionImp.begin(UserTransactionImp.java:115)
      at com.vs.framework.service.BlfServiceAtomIkosBean.executeService(BlfServiceAtomIkosBean.java:32)
      at com.dbhl.app.presentation.action.CreateUnitTypeAction.execute(CreateUnitTypeAction.java:128)
      at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
      at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
      at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
      at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
      at java.lang.Thread.run(Thread.java:662)
  com.atomikos.icatch.SysException: Error in init(): Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:333)
      at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:405)
      at com.atomikos.icatch.jta.UserTransactionImp.checkSetup(UserTransactionImp.java:100)
      at com.atomikos.icatch.jta.UserTransactionImp.begin(UserTransactionImp.java:115)
      at com.vs.framework.service.BlfServiceAtomIkosBean.executeService(BlfServiceAtomIkosBean.java:32)
      at com.dbhl.app.presentation.action.CreateUnitTypeAction.execute(CreateUnitTypeAction.java:128)
      at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
      at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
      at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
      at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
      at java.lang.Thread.run(Thread.java:662)
  Caused by: java.lang.RuntimeException: Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.createDefault(UserTransactionServiceImp.java:205)
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:265)
      ... 31 more
  Nested exception is: 
  java.lang.RuntimeException: Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.createDefault(UserTransactionServiceImp.java:205)
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:265)
      at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:405)
      at com.atomikos.icatch.jta.UserTransactionImp.checkSetup(UserTransactionImp.java:100)
      at com.atomikos.icatch.jta.UserTransactionImp.begin(UserTransactionImp.java:115)
      at com.vs.framework.service.BlfServiceAtomIkosBean.executeService(BlfServiceAtomIkosBean.java:32)
      at com.dbhl.app.presentation.action.CreateUnitTypeAction.execute(CreateUnitTypeAction.java:128)
      at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
      at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
      at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
      at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
      at java.lang.Thread.run(Thread.java:662)
  ERROR: the specified log seems to be in use already. Make sure that no other instance is running, or kill any pending process if needed.
  java.lang.RuntimeException: Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.createDefault(UserTransactionServiceImp.java:205)
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:265)
      at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:405)
      at com.atomikos.icatch.jta.UserTransactionImp.checkSetup(UserTransactionImp.java:100)
      at com.atomikos.icatch.jta.UserTransactionImp.rollback(UserTransactionImp.java:140)
      at com.vs.framework.service.BlfServiceAtomIkosBean.executeService(BlfServiceAtomIkosBean.java:80)
      at com.dbhl.app.presentation.action.CreateUnitTypeAction.execute(CreateUnitTypeAction.java:128)
      at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
      at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
      at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
      at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
      at java.lang.Thread.run(Thread.java:662)
  com.atomikos.icatch.SysException: Error in init(): Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:333)
      at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:405)
      at com.atomikos.icatch.jta.UserTransactionImp.checkSetup(UserTransactionImp.java:100)
      at com.atomikos.icatch.jta.UserTransactionImp.rollback(UserTransactionImp.java:140)
      at com.vs.framework.service.BlfServiceAtomIkosBean.executeService(BlfServiceAtomIkosBean.java:80)
      at com.dbhl.app.presentation.action.CreateUnitTypeAction.execute(CreateUnitTypeAction.java:128)
      at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
      at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
      at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
      at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
      at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
      at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
      at java.lang.Thread.run(Thread.java:662)
  Caused by: java.lang.RuntimeException: Log already in use?
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.createDefault(UserTransactionServiceImp.java:205)
      at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:265)
      ... 31 more
  Nested exception is: 
  </code></pre>
  
  <p>while i googling common solution from <a href="https://wso2.org/jira/browse/CARBON-10378" rel="noreferrer">here</a> </p>
  
  <pre><code>Are these instances running in a single machine? .. like, are those running in an app server, where it is pointed to a single CARBON_HOME? .. if so, the "transaction.properties" file have to be removed from /repository/lib and should be put into each WARs classpath location. And each "transaction.properties" file has to be edited to change the log file location. This error comes when more that one instance is trying to access the same transaction log file of Atomikos, or there's also a chance that the earlier JVM shutdown was not done properly and the lock file wasn't released. In that case, you simply have to remove the log file at /repository/data/tmlog.lck file and restart the server.
  </code></pre>
  
  <p>i follow this advise .
  remove property file from tomcat/common/lib to my war's classpath .
  changed directory accordingly above mentioned.
  i also check for tmlog file but it does not exist on the server. </p>
  
  <p>but nothing works . still the error occurs.</p>
  
  <p>if you see at atomikos page <a href="http://www.atomikos.com/Documentation/KnownProblems#Log_Already_In_Use" rel="noreferrer">here</a></p>
  
  <pre><code>The lock file in question is created to protect the transaction logs against accidental duplicate startups. Otherwise, the logs could get corrupted when two instances of the same transaction manager are recovering on the same data. Normally, it suffices to follow the hints and then delete the lock file manually if needed. 
  </code></pre>
  
  <p>it just states follow the hints , <strong>but where is the hint ??</strong></p>
  
  <p>please help me to re solve it.</p>
  
  <p>atomikos is the open source,</p>
  
  <p>i checked the source code and found the below lines which is throwing exception</p>
  
  <pre><code>if ( enableRecovery ) {
               //ISSUE 10077: don't complain about lock file if no logging
              try {
                  lockfilestream_ = new FileOutputStream ( lockfile_ );
                  lock_ = lockfilestream_.getChannel().tryLock();
                  lockfile_.deleteOnExit();
              } catch ( OverlappingFileLockException failedToGetLock ) {
                  //happens on windows
                  lock_ = null;
              } catch ( IOException failedToGetLock ) {
                  //happens on windows
                  lock_ = null;
              }
              if ( lock_ == null ) {
                   System.err.println ( "ERROR: the specified log seems to be "
                          + "in use already. Make sure that no other instance is "
                          + "running, or kill any pending process if needed." );
                  throw new RuntimeException ( "Log already in use?" );
              }
          }
  </code></pre>
  
  <p><strong>i have already set debugging to false in jta.properties
  com.atomikos.icatch.enable_logging=false
  and restart my server but still the same error.</strong></p>
  
  <h2>Update after Guy Padron Answer</h2>
  
  <blockquote>
    <p>@Guy Pardon thanks for this answer.i know you are the owner of the
    AtomIkos , i am often get mail from you. the problem is that for your
    free open source version you hard coded default properties in the code
    , so if any user ties to set it from the property file it is not
    overriding. in my case what was the problem , the log file is created
    in the current directory by atomikos by its default properties and
    hence no problem on the local environment but whenever it is uploaded
    to shared hosting where creating is file or directory inside server's
    bin folder is not permitted and hence the above error, so i debug the
    code , modify it according to my need and got success in Aug,2012.
    when i inspect your code i found that your code is throwing wrong
    exception in my described situation as well and there are so many
    points the code can be improved.</p>
  </blockquote>
  
  <p>Thank You
  Mihir Parekh</p>