How to connect one database in two threads?

Dear All,
If anyone can tell me how to connect one database concurrently?
I tried the following idea:
1.create a Hashtable to keep database objects(those databases have been opened)
2.Before openning(connecting) a database:first step is to check the hashtable.
If the the database object is in the hashtable, this object will be returned.
If the datatbase object is not in the hastable, open the database and store this opened database object into the hashtable.
I failed the test of this implementation. My test is:Create two threads (extend java Thread class).In each of these two threads, try to open the same database.Just like the following:
MyThread thread1 = new MyThread();
MyThread thread2 = new MyThread();
thread1.start();
thread2.start();
I guessed the database object in the hashtable would be returned in the second thread.Unfortunatly, I only got an exception which meant the database couldn't be opened twice.It looks like the second thread happened before the opened database object stored into the hashtable.
I cannot figure out if my design is wrong or my test application is wrong.
I really appriatiate your attentions!!!
Lu

um not sure i follow exactly but in your code add the word synchronise to it and this means only 1 tread can access it at any 1 time.
So your could have a class which is a singleton so it only opens the dbase once and then all other access share your connection.
so
public class foo{
foo INSTANCE = new foo();
private foo(){} //private constructor
then all your methods use foo's internal dbase connection. Am i making sense

Similar Messages

  • How  to  connect  to  database

    Hi Experts,
    i am using oracle 10g (10.2),linux4.6 .my databae server contain multiple databases how can connect one database to another database and how can i put this all environment variable in single parameter file

    tmadugula wrote:
    Hi Experts,
    i am using oracle 10g (10.2),linux4.6 .my databae server contain multiple databases how can connect one database to another database and how can i put this all environment variable in single parameter fileYou can see from the responses two very different sets of advice. To know what applies to your situation, you need to clarify what you need to do.
    If you are talking about choosing which database you connect to from sqlplus, follow the advice about changing the environment variable ORACLE_SID.
    If you are talking about having one database being able to access another (one db acts as the client to another) follow the advice about db links.

  • How to connect oracle database from tuxedo

    Hi,
    How to connect oracle database from tuxedo.
    If any one can help me.
    Regards,

    it depends on configuration your going to choose, there are two ways--
    - Using X/Open standards, for this
    you have to make an entry of Resource manager in $TUXDIR/udataobj/RM file.
    Then in UBBConfig file in GROUPS section u have to set Openinfo.
    It also depend on which database you are going to use.
    In your service now you need to call tpopen() API from tpsvrinit() function.
    - Other possibility is, take an implicit connection using Pro*C or Pro*Cobol whatever platform you are using.
    EXEC SQL Connect ...

  • How to connect mysql database using xml

    welcome to all,
    here my doubt is how to connect mysql database using xml file, how to integrate xml file and jsp file and how to access data from dabase using jsp file. can any one help me
    regards

    Short answer: you wouldn't do any of those things. The first two are meaningless and the third is a bad practice. I have no idea what those ideas were supposed to achieve so I have no idea what tutorials I should suggest to you.

  • Getting connection toa database in a thread

    Hi
    I need guidance on how to get connection to a database inside a thread.Let me explain in detail.
    I am developing a chat application. As normal my chat server assigns each user an instance of a chathandler class which runs as a thread.The problem is that i need to connect to database inside this thread to implement some group wise logic in the broadcast method of chathandler thread.
    Now for this can i create a connection object each time in the thread or can i use a common connection object ? If i go for the second method will it cause any concurrency issue ?
    Thanks in advance

    Hi
    I need guidance on how to get connection to a
    database inside a thread.What other way is there? You always get access to a database inside a thread.
    Let me explain in detail.
    I am developing a chat application. As normal my
    chat server assigns each user an instance of a
    chathandler class which runs as a thread.The
    problem is that i need to connect to database inside
    this thread to implement some group wise logic in
    the broadcast method of chathandler thread. No, database connections are for persistence. Group wise logic belongs somewhere else.
    Now for this can i create a connection object each
    time in the thread Yes, for each database access. Create it, use it, close it. Use a connection pool to amortize the cost of opening a connection.
    or can i use a common connection object ? If you're foolish you can. How scalable is an app with one connection?
    If i go for the second method will it cause
    any concurrency issue ?You'll have isolation and concurrency issues to worry about in any case.
    %

  • How to connect external database(Ex:SQL Server/Tivoli)  from ABAP Webdynpro

    Hi,
    Any one have idea how to connect external database like SQL Server/Tivoli to access tables from WebDynPro ABAP.
    Please point to me some links if you have
    Thanks
    Praveen

    Hi,
    Please check out this link -
    FETCH DATA FROM ORACLE DATABASE USING Web Dynpro
    Regards,
    Lekha.

  • How to connect oracle database using jsf

    how to connect oracle database using javaserver faces with connection pooling

    Here is one way...
    http://jakarta.apache.org/commons/dbcp/

  • How to connect oracle database into VC?GIve step by step.

    Hi Experts,
    Please help
    How to connect oracle database into VC?
    I need step by step.
    what shall i do the first to connect via jdbc or  something else.
    whether we have to create dsn name or using jdbc connections?which one to use?
    Please give the basic steps.Its very urgent.
    Thanks and Regards,
    Nutan

    Hi ,
    all information are in the following document:
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6209b52e-0401-0010-6a9f-d40ec3a09424">How to Configure a Business Intelligence JDBC System for Visual Composer</a>
    Rgds,
    Karim

  • How to connect another database

    I have installed ORACLE 10g database express edition and want to connect to another oracle 8i database, that have installed at server how to connect.

    One way is add a TNS alias to your tnsnames.ora file, like this stanza:
    EXAMPLE =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = SAMPHOST.mydomain.com)(PORT = 1521))
    (CONNECT_DATA =
    (SID = SAMPLSID)
    (SERVER = DEDICATED)
    So in sqlplus ...
    SQL> connect username/passwd@example
    will connect you to the database with ORACLE_SID -> SAMPLSID via port 1521 at samphost using a dedicated server connection.

  • Hello, I would like to know how to transfer one of my two "membership" to an other computer because I just bought a new Mac.... ? Or how to cancel it on my old laptop so I can activate it on my new computer. Thanks a lot !

    Hello, I would like to know how to transfer one of my two "membership" to an other computer because I just bought a new Mac.... ? Or how to cancel it on my old laptop so I can activate it on my new computer. Thanks a lot !

    Hi Virginie,
    You need to go under the help menu option and sign out from Muse and then install it on the other computer that you want using the creative cloud desktop app.
    - Abhishek Maurya

  • How to connect sybase database in JDeveloper 11g using JConnect

    Hi
    How to connect sybase database in JDeveloper 11g using JConnect? Please help.

    User,
    It would help if you explained Sybase Jconnect instead of leaving us to google.
    At any rate, it appears you need to create a library definition in JDeveloper, add the appropriate JConnect JAR files to the library's classpath, and then add the library to your project.
    John

  • How to connect Oracle database in VC++.06

    How to connect Oracle database in VC++.06 please give me details

    on the Insert command button and add the following code to the button click event:
    try
    string results = "";
    OracleConnection con = new OracleConnection("DSN=Employee;uid=system;pwd=test");
    con.Open();
    .....................................................................

  • How to connect oracle database with JAVA

    how to connect oracle database with JAVA....
    using j2sdk and Jcreator . which connector to use .. what are the code for that ..

    PLEASE .... Ask in an Oracle Java forum.
    And read the documentaiton. There is a whole document devoted to doing that. http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/toc.htm has examples.
    PLEASE ... do not ask product questions in a forum which clearly has a title saying it is devoted to assisting with download problems.

  • How to connect one SAP system to Non-SAP system(Example:Window's7)?

    Hi Experts,
        In general, One SAP system can connect another SAP system through RFC.How to  connect One SAP system  to Non-SAP system(example:window's 7) and is it possible through RFC?
    Thanks and Regards,
    Nageswar

    Hello  Wolfgang Schaper,
    Thank you so much for quick response.
    As you told I am trying to work with BRFplus/DSM to call decision services from nonABAP systems,so I tried with RFC.But it is not possible as you told.
    Please give any solution Without using Web Services, is there any ways to connect from SAP system  with the Non-SAP Systems.

  • How to connect one page using button and by link in BSP

    how to connect one page using button and by link in BSP

    hi,
    use on 'onclick' functionality.
    1. In layout, onclick = 'NEXT_PAGE' of the button
    2. Capture the event in onInputprocessing,
    DATA: event_id TYPE REF TO  cl_htmlb_event.
    case event_id.
    when 'NEXT_PAGE'.
                navigation->goto_page( 'URPAGE URL' ).

Maybe you are looking for

  • Http 404 Error while trying to get the plug-in

    Hi, We have installed the Developer server 6i, and everything was working fine with jinitiator 1.1.7.30. Recently we have installed Patchset 3A on the machine on which Developer Server was installed and downloaded jinitiator 1.1.8.3. When we try to r

  • Officejet pro 8600 paper will not feed , Starts to feed and then jams before getting to printer head

    officejet pro 8600. Has been flawless for 2 years. Now it start to feed the paper, but jams as the paper goes around to the printer. It seems like the paper goes straight up instead of curving aroun to the printer head.

  • Lost audio files after saving.

    I lost my audio files after saving in Logic X and now my project file has the extension .logicx on it and my audio files are nowhere to be seen. I made some changes to the project, moved the file to another folder, then they asked if I wanted to repl

  • Sap ECC 6 Install on Oracle and Aix 5.3

    Dear All Please have any document for installation sap ecc6 on oracle/ Aix 5.3 , please give me or send link Nainesh

  • SAP Implementation for a building construction company

    Dear All ,                We are doing SAP implementation for a building construction Company .My client is responsible for building construction .What they do is initially some 10 members of this Company will create a society(Legal Entity)  .They ar