Atomikos Forum

Resource already exists

Hi,

I am getting an error "Another resource already exists with name XA1 - pick a different name" with the two scenario listed below.

AtomikosTransactionsEssentials-3.4.0
Oracle 11 driver
Spring Batch
Have two datasources XA1 and XA2.
Launcher (java class) executes batch jobs.

Scenario-1 (Launcher class executes only one job)
-Local (Windows) unit tests pass with/without "init-method="init" destroy-method="close""registeration with DataSources and UserTransactionManager.
-IBM/AIX deployment without "init-method="init" destroy-method="close""passes. Job runs successfully.
-IBM/AIX deployment with "init-method="init" destroy-method="close""fails with the error message "Another resource already exists with name XA1 - pick a different name". This error happens when i try to run the launcher. Launcher fails while creating instances of the registered beans. Hence, job did not run. What am i missing with the configuration?


Scenario-2 (Launcher class executes two batch jobs one after another in sequence.)
-IBM AIX Deployment
-"init-method="init" destroy-method="close"" is not registered.
-The first job executes successfully.
-Then launcher picks up the second job for execution. It fails with "Another resource already exists with name XA1 - pick a different name".
-Launcher gets terminated as no more jobs to excute.
-When i restart the launcher, it picks the 2nd job that was failed before and completes the execution succesfully.
-Looks like that the resource name was not release after successful completion of the first job. What fix do i need here? How do i release the resource?

Thanks for the help!

Hiren
springforever Send private email
Monday, December 22, 2008
 
 
Hi,

Sounds like a bug we fixed in the 3.4 branch already. Did you try with 3.4.4 (now online)?

Guy
Guy Pardon Send private email
Monday, December 22, 2008
 
 
Hi Guy,

I did some more testing and could replicate the scenario-1 on windows by putting together all the modules that i ran on IBM AIX. Error "Another resource already exists with name XA1 - pick a different name" occured on local as well. I am using 3.4.4 and running the actual job as it runs on IBM AIX.

This one i figured that it was the configuration failure with the bean registeration. The similar registeration works for other non-atomikos beans. However, i moved the atomikos beans in some other config files. I no more get "Another resource already exists with name XA1 - pick a different name".

Now, with "init and close", i get "Invocation of init method failed; nested exception is com.atomikos.jdbc.AtomikosSQLException: Cannot initialize AtomikosDataSourceBean" and this error is consistent on local as well as IBM AIX. This error occurs when the beans are getting loaded/initialized through spring xml files. If i drop "init and close" then there are no errors for the scenario-1.

Any input will be of great help! The atomikos configuration is as below.

Thanks,
Hiren
springforever Send private email
Tuesday, December 23, 2008
 
 
<!-- Construct Atomikos UserTransactionManager START-->
    <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
          init-method="init" destroy-method="close">
         
      <!--  when close is called, should we force transactions to terminate or not? -->
      <property name="forceShutdown" value="false" />
      <!--  <property name="startupTransactionService" value="true" />  -->         
    </bean>
    
    <!-- Also use Atomikos UserTransactionImp, needed to configure Spring  -->
    <bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
      <property name="transactionTimeout" value="300" />     
    </bean>
    
    <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
    <bean id="JtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
      <property name="transactionManager" ref="AtomikosTransactionManager" />
      <property name="userTransaction" ref="AtomikosUserTransaction" />     
      <property name="transactionSynchronization" value="2" />
    </bean>
    
    <bean id="xaDataSourceE1Ref" class="com.atomikos.jdbc.AtomikosDataSourceBean"
            init-method="init" destroy-method="close">
        <property name="uniqueResourceName"><value>XAE1</value></property>        
        <property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource" />
        <property name="xaProperties">    
            <props>            
                <prop key="URL">jdbc:oracle:thin:@dev:1521:mydev</prop>
                <prop key="user">abc</prop>
                <prop key="password">password</prop>                            
            </props>
        </property>
        <property name="poolSize"><value>30</value></property>
        <qualifier value="xaDataSourceE1Ref"></qualifier>
    </bean>    
    
    <bean id="xaDataSourceE2Ref" class="com.atomikos.jdbc.AtomikosDataSourceBean"
            init-method="init" destroy-method="close">
        <property name="uniqueResourceName"><value>XAE2</value></property>        
        <property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource" />
        <property name="xaProperties">
            <props>            
                <prop key="URL">jdbc:oracle:thin:@dev:1521:mydev</prop>
                <prop key="user">xyz</prop>
                <prop key="password">password</prop>                            
            </props>
        </property>
        <property name="poolSize"><value>30</value></property>
        <qualifier value="xaDataSourceE2Ref"></qualifier>
    </bean>        
    
    <!-- Construct Atomikos UserTransactionManager END-->
springforever Send private email
Tuesday, December 23, 2008
 
 
tm.out log has

"08-12-23 12:42:06,218 [main] Cannot initialize AtomikosDataSourceBean
javax.naming.NamingException: Another resource already exists with name XAE1 - pick a different name

    at com.atomikos.util.IntraVmObjectFactory.createReference(IntraVmObjectFactory.java:69)
"
springforever Send private email
Tuesday, December 23, 2008
 
 
The NamingException was due to the batch process trying to create the instance of AtomikosDataSource two times as the config file was called twice.

Thank you for your time!
Hiren
springforever Send private email
Tuesday, December 23, 2008
 
 
Thanks for the update; I created a case in our issue tracker but I guess now it can be closed.

Any specifics you can provide to avoid other people having the same problem?

Thanks
Guy Pardon Send private email
Wednesday, December 24, 2008
 
 
Guy,

I am still doing some analysis to find the best solution at my end. I will add more details in few days.

I think i know why it used to work without "init, close" registration and why it used to fail for scenario-2. But to come to any conclusion i need some inputs.

When getConnection() is called on AbstractDataSourceBean through Spring then init() gets called. So even if we have not registered "init", it still works. Shouldn't be close() called in someway with a method like closeConenction() in AbstractDataSourceBean, without registering "close" with the bean?
springforever Send private email
Wednesday, December 24, 2008
 
 
Hi,

We call init() upon the first getConnection(). The same logic does not work for the close, because the essence of pooling requires that connections be reused after they are 'closed' by the application.

In other words: what you suggest is impossible because we can never know when the connection.close() also means datasource.close(). It is indistinguishable from the normal connection-reuse scenario.

Guy
Guy Pardon Send private email
Friday, December 26, 2008
 
 
After the following steps everything started working smoothly.
1. Created a separate configuration file for atomikos properties and made sure that this file is being loaded only when required. Earlier, i had these beans in the common dataSource files.
2. I had not registered init and destroy properties as with my set up it was throwing "can not create AtomikosDataSourceBean" error.
3. I was using config files to look up name of the jobs. Now, i am destroying this context after reading name of the job.

Hope it helps anyone who come across this kind of problem.

Thank you,
Hiren
springforever Send private email
Thursday, January 15, 2009
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics