Does JNDI always return the same DataSource reference for a connection pool

Hi,
In my project, I have a class called DBConnect which has a method called
getConnection(). This method returns a data base Connection object from the
pool. I am doing this to avoid replicating code.
Here, each time a database connection is required this method looks up for
the pool using JNDI , gets the DataSource and then gets the data base
connection.
What I want to know is that, can I get this DataSource reference only once,
store it in an instance variable and use the same value for getting the
connections when ever needed. This wud reduce the overhead of making the
lookup each time.
but wud this lead to probs. is there a threat of having a stale reference.
Or is there a better way to do this.
Thanks,
Manohar

Hello,
In our EJBs, we successfully cache the DataSource object as an instance
variable. Since bean access is synchronized, the concurrency issue Jeff
Wang mentioned is dealt with.
Eron
"Manohar" <[email protected]> wrote in message
news:[email protected]..
Hi,
In my project, I have a class called DBConnect which has a method called
getConnection(). This method returns a data base Connection object fromthe
pool. I am doing this to avoid replicating code.
Here, each time a database connection is required this method looks up for
the pool using JNDI , gets the DataSource and then gets the data base
connection.
What I want to know is that, can I get this DataSource reference onlyonce,
store it in an instance variable and use the same value for getting the
connections when ever needed. This wud reduce the overhead of making the
lookup each time.
but wud this lead to probs. is there a threat of having a stalereference.
>
Or is there a better way to do this.
Thanks,
Manohar

Similar Messages

  • GUID generation issue, SYSUUID always returns the same value.

    Hi,
    I'm using "SELECT SYSUUID FROM DUMMY" to get a guid value but it always return the same value.
    What should I do to get a unique value each time I execute the query above.
    Thanks.

    I thought I had the same problem and I found that if you generate multiple UUID's in the same SQL, it they will be the same.  If you make multiple calls, you should get multiple UUID's. 
    Try this:
    SELECT SYSUUID as UUID1 FROM DUMMY;
    SELECT SYSUUID as UUID2 FROM DUMMY;
    I get the following results:
    UUID1 = 538632FD7EA20426E10000000A3F10A9
    UUID2 = 538632FE7EA20426E10000000A3F10A9
    Notice that the strings look almost identical, but the 8th character on UUID1 is a D and the 8th on UUID2 is a E.
    Jim

  • Context.lookup in a Servlet always returns the same Stateful Session Bean

    Hi,
    I am working on an application in which a Servlet should obtain one StateFul Session Bean per client. I read in EJB 3.0 in Action that to do so I should use a jndi lookup and save the result of the lookup in an HttpSession. This works fine for me when I have a single client.
    My issue is that when I have several clients, context.lookup returns the same SFSB for each client. This means that I end up having a single SFSB for the whole application. I've been browsing the web for a while now trying to find a solution but haven't had any luck yet.
    The code I use to obtain and save the SFSB is the following:
    HttpSession session = request.getSession(true);
    DFMServiceRemote service = (DFMServiceRemote) session.getAttribute("DFMService");
    if (null == service)
         service = (DFMServiceRemote) new InitialContext().lookup("DFMService");
         session.setAttribute("DFMService", service);
    }Using different browser, I end up with different HttpSession but a single SFSB. The only workaround I found is to create the context with environment variables or properties. It then returns different SFSBs for different HttpSession. The workaround code is as below:
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin");
    env.put(Context.SECURITY_CREDENTIALS, "welcome");
    env.put(Context.PROVIDER_URL, "ormi://localhost:23791/DriverFatigue");
    service = (DFMServiceRemote) new InitialContext(env).lookup("DFMService");My question is the following. How can I get a different instance of an SFSB every time I execute context.lookup without specifying properties.
    Thanks in advance for any help,
    Matthieu Siggen

    I just did something similar in another project using JBoss instead of oc4j and didn't have any problem. I expect I missed a configuration file in oc4j or there is a conflict somewhere.

  • WRT54GS: without Windows, force a given MAC address to always get the same IP address via DHCP?

    I have just now set up my WRT54GS to manage my home wireless network, and it works great. I just have one question that I haven't been able to find an answer for (forgive me if I have overlooked an obvious source of information).
    I have set up the WRT54GS to be a DHCP server, and it assigns addresses in an ad hoc manner to all the devices that connect to it. In general, this is what I want, but in one case, I want a certain host to always get the same IP address, for example, 192.168.1.10.
    You should know that I have no Windows machines on my network. Everything is either running Linux, MacOSX, or Symbian (on a Nokia N95 handheld). Therefore, I can't set up a static IP for my device using the software supplied on the CD that comes with my router, as that software only runs under Windows.
    Using a different manufacturer's router, I am able to accomplish this by telling the DHCP software on that router to always assign 192.168.1.10 to the host who connects with a certain MAC address. I can then use this mechanism to force my specific host to always get this desired IP address. However, I haven't been able to find any way to do that with the WRT54GS without the software on the Windows-based CD. Is it possible at all? If I can indeed do this without that Windows software, could someone point me to some docs which explain how to accomplish this?
    ... or is there perhaps a different way to cause this to happen, perhaps by means of some sort of DHCP client ID?
    Thank you very much in advance for any pointers you can give me.
    Message Edited by HippoMan on 10-16-2007 05:27 PM
    Take a hippopotamus to lunch today.

    Forget about the CD. There is nothing on the CD which you don't configure better through the router web interface at http://192.168.1.1/ You don't need the CD. Never. I have never used the CD to configure any of my routers. The program on the CD is just a software which helps you with the initial configuration of the router. It is just a software which pretty much contacts the web interface in the background and sends some settings changes there. You can do everything yourself directly. Then you know what you change.
    You have to configure the static IP address on the computer and on the computer only, e.g. on your Mac use Static IP instead of DHCP in the network preferences. Enter the IP address you want to use for the computer, the subnet mask, gateway address and DNS server(s). That's it. The router is not involved in any of this.
    You just have to make sure that you use an IP address inside the LAN of the router. By default, Linksys routers use the IP address 192.168.1.1 on the LAN side for the the router. The subnet mask is 255.255.255.0. The IP address together with the subnet mask says that all IP addresses 192.168.1.0-255 are considered part of the LAN. Everything else is outside and needs to be routed to the router and from there into the internet. (If you want to know how the subnet mask works exactly read the wikipedia article on it or search for "subnet calculator" or similar in the internet)
    Thus, if you connect a computer to your LAN and set a static IP address on the computer it should be inside this IP address subnet/range in order to have internet and LAN access on the computer. It does not matter which address you use as long as it is inside the IP subnet. The DHCP server on the router automatically assign a correct IP address inside the IP subnet and also automatically assigns the correct gateway address (its own address = the address to which everything should be sent which does not belong into the LAN, i.e. the internet traffic) and the DNS server. With static IP you have to assign those values yourself.
    But again, there is no Windows computer or CD involved to do that nor is there any configuration on the router required to set the static IP address on the Mac. The IP address you set must simply match your LAN IP which is basically defined through the settings on the router as you want to have internet and thus need access to the router and its address 192.168.1.1.
    Some routers allow you define fixed IP addresses for specific devices in the DHCP server of the router. With that function you can set a fixed IP address on the router. The computer can remain on DHCP. It will always get the IP address you have configured in the list on the router through the DHCP server. However, your Linksys router does not have this option. If any device inside your LAN is supposed to receive the same IP address at any time you have to configure that on the device only.
    If you have not changed the default LAN IP address, subnet mask and DHCP server settings on the router, the router has 192.168.1.1, subnet mask 255.255.255.0 and the DHCP server uses 192.168.1.100-149 for dynamic assignments. To avoid potential address conflicts you should not use any static IP addresses inside the DHCP server address pool. This leaves you with IP addresses 192.168.1.2-99 and 150-254 as static IP addresses inside your LAN. You can pick any address you like as long as any device with a static IP address has a unique IP address inside your LAN.
    Assign the subnet mask 255.255.255.0 on the computer and set the default gateway to 192.168.1.1. The DNS servers are a little bit more complicated. Generally it is better and faster if you use the DNS servers of your ISP. You can, however, also use the IP address of the router 192.168.1.1 as DNS server. The router will then operate as DNS proxy, i.e. it contacts the DNS servers of your ISP for any request from your computer.
    If you want to use the DNS servers of your ISP, click on the Status tab in the router web interface. It shows you the current settings of the router on the internet port. It should show you multiple entries for DNS servers. Choose those DNS server IP addresses in the computer.
    If you don't want to go through the hassle with the direct access to the DNS servers of your ISP, simple use 192.168.1.1 as only DNS server on the computer.
    There are all settings you have to make on your Mac or other computers to assign a static IP address. As long as the IP address is inside 192.168.1.* it belongs to the LAN and has internet access through the router (as long as the default gateway address is 192.168.1.1 of course).
    Firmware is loaded either through the web interface of the router, usually somewhere on the Administration tab or with tftp. Both ways work fine on any Mac or Linux box.

  • When I "Get Album Artwork", iTunes always returns a result that artwork for one song could not be found; but the song is not in my library.

    When I "Get Album Artwork" in  iTunes 10.4.0.80 running under Windows 7, iTunes can find the missing artwork requested.  But it also returns the same result, "Artwork for "Aught 7 - Mother Chorizo" could not be found.  The problem is I do not have the song or any song from Aught 7 in my music library.  I'm guessing this is an issue with a corrupted iTunes database.  Can someone tell me how to correct this issue?
    Thanks in advance.

    1. delete this songs from your liblary
    2. go File -> Add File to Liblary... (Ctrl+O) or File -> Add Folder to Liblary

  • I have been using the same debit card for iTunes forever and now it's saying its declined but it hasn't expired yet

    I Have always used the same debit card for iTunes and then the other day I tried to download an app and it said that I needed to update payment methods so I put in all of my details and it said that my card had been declined. I have no idea why and I don't know how to fix this. Please help

    Is the address on your iTunes account exactly the same (format and spacing etc) as on your credit card bill : http://support.apple.com/kb/TS1646 ? If it is then you could try what it says at the bottom of that page :
    If the issue persists, contact your credit card company and verify that they and any company they use to process credit card authorisations have the correct information on file.
    And/or try contacting iTunes support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • Where does Sting to IP get the net address if the computer is disconnected from the net? It should return the same I

    P/Net address� it did not change. Internet Protocal(TCP/IP) Properties did not change. When the network is physically disconnected, my VI after several runs returns 127.0.0.1. So, how do I get my IP address whether it�s connected to the network or not?Thanks in advance for your help.

    P/Net address� it did not change. Internet Protocal(TCP/IP) Properties did not change. When the network is physically disconnected, my VI after several runs returns 127.0.0.1. So, how do I get my IP address whether it�s connected to the network or not?If you're getting a dynamically assigned IP address from the network, then String to IP will return that IP but it may not be constant. See if TCP/IP properties are set to "Obtain an IP address automatically". If you disconnect from the network, then the IP address will default to something and I wouldn't be surprised if the default is 127.0.0.1. If you want to always have the same IP, then the ICP/IP properties should be changed to use a fixed IP but you'll certainly need to check with your IS department before doing so.

  • Hi. My husband and I have always shared the same iTunes account.  Since installing iCloud, all our contacts and calenders have merged on our iPhone 4, which we do not want.  How do I rectify this? Does my husband need to set up his own apple ID?

    Hi. My husband and I have always shared the same iTunes account.  Since installing iCloud, all our contacts and calenders have merged on our iPhone 4, which we do not want.  How do I rectify this? Does my husband need to set up his own apple ID?  If so, where do I need to change his email address info, so that his calender and contacts remain his?  Thank you

    You can continue to use the current AppleID for iTunes, but your husband can create a new AppleID to use to create a new iCloud account that will be his own and not overlap with yours.  If you do not have another email address to use for an AppleID, just get a free Gmail account and use that.
    You can have as many AppleIDs as you want (or at least, as many as you have email addresses for).  You can use a separate AppleID for the store, another for iCloud, and even another for iMessage if you wish.
    You will want to keep the current one as the shared one for the store as all your previous purchases are permanently tied to it, and thus you need that AppleID to update or redownload your current purchased content.

  • Iphone 5-updated to ios 7.0.2 keeps freezing in lock screen.I always need to restart or should wait till a phone call come to unlock the screen. Does any body have the same issue??

    Iphone 5-updated to ios 7.0.2 keeps freezing in lock screen.I always need to restart or should wait till a phone call come to unlock the screen. Does any body have the same issue??

    I do have the same issue with my 4s after updating.tried with restoring several times,but the problem still persists.....

  • Why does my brand new printer always print the same 1. thing that i printed before

    when i try to print something else it always prints the same thing i dont know why i deleted that old files but it still prints the old thing

    I would check to make sure the print queue is empty. I would also check the temp files on the computer (and anywhere else that a copy of it could exist depending on what operating system you are using) for that print item. 
    Also, make sure there is not a virus on the system. Those can do some weird things when certain conditions happen. Not likely just not something to overlook.
    007OHMSS
    I was a support engineer for HP.
    If the advice resolved the situation, please mark it as a solution. Thank you.

  • Why my vector() always always return the last record?

    Whenever i uses Vector, my whole vector always return the last element.. why?? Anyway to solve this?
    some examples of my codes..
    (String)rowVector.elementAt(2)
    My rowVector vector always return the last element..
    while(rs1.next())
    Vector rowVector = new Vector();
    for (int currentCol = 0; currentCol < numCols; currentCol++)
    rowVector.add(rs1.getString (currentCol + 1));
    tableData.addElement(rowVector);

    That means that every element in the Vector refers to the same object. I am surprised that your JDBC driver does not return different string objects for each call, but to work around that, try this:
    rowVector.add(new String(rs1.getString (currentCol + 1)));

  • Multiple domains share the same datasource?

    Hi,
    I'm new to weblogic server. I understand that there's a wizard available for us to follow and have the domain created. However, does it means that only one domain can be tagged to the datasource (meaning the database used). Can I recreate or clone this admin server, yet having the same datasource in used. The reason is because I need to have another instance available for quick test and yet do not wish to spend too much time on the domain setup, etc.
    Appreciate any advise on this.
    Cheers

    You can just copy your directory and put it on another machine (for example). If you keep it on the
    same machine, you have to make sure the ports used by servers are different. Note also you
    cannot have domains of the same name on the same machine.
    When you installed the environment in production mode you have to disable hostname verification.
    As WebLogic per default uses a self-generated certificate, which has the hostname of the machine
    in it on which the domain was configured.

  • After the newest update, i can no longer type in traditional chinese ( pin yin), does anyone else have the same problem?

    after the newest update ( iso 7) , i can no longer type in traditional chinese ( pin yin), does anyone else have the same problem?

    I downloaded and tried EasyFind. It works but it took 30+ seconds to complete finding 3 files that are on One of my Five 25+ Gb partitions of my 130 Gb Seagate Cuda(Really 160 Gb, but my Sawtooth will only recognize 130) I figured that if I ever got a better box, I could reformat it to see the whole 160 Gb. So, as far as I can see, Spotlight's indexing scheme which finds the files instantly is probably preferable. Spot light allows you to rename your files from within it's app window. I've always thought that was pretty powerful. Could my doing so be causing me any issues? As i said it is the inability to Type in the Finder that seemed to be caused from changing file Extentions that were mis-written. Maybe it was a delayed reaction to my renaming files in the Spotlight app? I've done both on occasion.
    As for these .DS_Store files. Apparently you can NOT stop them from being written to any folder that you touch/open/view during a days session. But, as a function of the OS, are the essential to have in their respective folders Forever? I've looked at the .DS_Store terminator app briefly and assume that getting rid of these files won't hurt the regular operation of my OS. They will just be re-written if I ever have to go back to any particular folder again. But, apparently, some have said that if the plan on burning a CD or DVD of their data, they delete the .DS_Store files first and then do the burn.
    I'm thinking from your having suggested this tremination app that you suspect that my having all of these ,DS_Store files could be a situation where any of them could have become corrupted and terminating them regularly should be part of my regular maintenance.
    Does that sound like I'm understanding what I can do?
    TIA

  • Make a file extension to open always with the same app

    Hello, do you know how can I make a file extension to open always with the same app. So far I have been doing it by double click > open with > other > and then mark open always with this app, BUT
    I do not want to do this very time with all the same file extension I have in my hard disk, is there any way, like in windows, to select and preset a determined app to always open all files with the same extensión in my hard disk??
    Actually what I´m experiencing and would like to change is to open always .pdf extensión with Acrobat and not with Preview
    Thanks very much in advance for your help!!

    OK!!!!
    Got it!!!
    Thanks anyway!!

  • Firefox always uses the same session id

    Hi,
    our company changes standard browser from IE6 to Firefox 3.5.10 .
    Now we have  great problems with with our ColdFusion application when running it inside Firefox ,because Firefox doesn't create new session id
    when working  in two tabs or two windows. It always uses the same cfid and cftoken.
    So it is not possible to work with two different sessions.
    IE6 always creates new session id when opening new window.
    Has somebody solved this problem? It is very urgent!!!
    regards
    Claudia

    I suspect that this is browser issue, not a server-side (CF) issue.  In order to support different cookies in different tabs you will probably need to try to find a Firefox extension to change how the browser uses cookies.
    This extension is advertised as doing what you need.  Note that I have never used this product.
    http://www.nektra.com/products/cookiepie-tab-firefox-extension

Maybe you are looking for

  • Apple wireless keyboard isn't working on fresh Windows 7 Boot Camp except in safe mode

    OK so yesterday I decided to reinstall Windows 7 to my mid 2011 27 inch iMac. I've had Windows 7 on it for a couple years but it got so bogged down that I wanted to start from scratch. However once I finished installing all of the Boot Camp 5.0 drive

  • Posting Partial payment for Invoice and manually clearing the Items

    item 1 Balance of 1st bill-24000 Item 2 Incoming payment  - 20000 Item 3 Adjustment        - 2000 These 3 items appears as open items in the Vendor Line item display. But when i try to clear the vendor account manually using F-32. The item 1 should c

  • [Flex mobile] Open file with a Filebrowser

    Hi everyone, i want to be able to open files with a file browser in my app, but the browse dialog which is opened by the File.browse() method only displays / opens music or image files. Furthermore im not even able to change the Dialog header when ru

  • Console application problem

    Hi all; I have a problem. I wanna build a console application in Java but although I write "Console c = System.console();" statement , console c is never be created. How can I overcome this problem? I thought that my virtual machine does not contain

  • Mac Book Pro slow after downloading Yosemite

    Downloaded Yosemite now computer is too slow. Barely able to use it but i ran an Etrecheck test and here are the results. Problem description: every EtreCheck version: 2.1.3 (106) Report generated December 15, 2014 at 8:24:59 PM PST Hardware Informat