Can't access ejb with more than 1 person at the same time?

I am using the ejb to access the database using DBConnection Pool that I find in book. The code is as follow:
The problem is when more than one user access almost at the same time, the one who enter frst can access, but the other one can't and return context lookup error in creating EJB.
What's the problem of it, is it the ejb concurrent access problem or database concurrent access problem?
package login.database;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
public class DBConnectionManager {
static private DBConnectionManager instance;
static private int clients;
private Vector drivers = new Vector();
private PrintWriter log;
private Hashtable pools = new Hashtable();
static synchronized public DBConnectionManager getInstance() {
if (instance == null) {
instance = new DBConnectionManager();
clients++;
return instance;
private DBConnectionManager() {
init();
public void freeConnection(String name, Connection con) {
DBConnectionPool pool = (DBConnectionPool) pools.get(name);
if (pool != null){
pool.freeConnection(con);
public Connection getConnection(String name) {
DBConnectionPool pool = (DBConnectionPool) pools.get(name);
if (pool != null) {
return pool.getConnection();
return null;
public Connection getConnection(String name, long time) {
DBConnectionPool pool = (DBConnectionPool) pools.get(name);
if (pool != null) {
return pool.getConnection(time);
return null;
public synchronized void release() {
if (--clients != 0) {
return;
Enumeration allPools = pools.elements();
while (allPools.hasMoreElements()) {
DBConnectionPool pool = (DBConnectionPool) allPools.nextElement();
pool.release();
Enumeration allDrivers = drivers.elements();
while (allDrivers.hasMoreElements()) {
Driver driver = (Driver) allDrivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
log("Deregistered JDBC driver " + driver.getClass().getName());
} catch (SQLException e) {
log(e, "Can't deregister JDBC driver: " + driver.getClass().getName());
private void createPools(Properties props) {
Enumeration propNames = props.propertyNames();
while (propNames.hasMoreElements()) {
String name = (String) propNames.nextElement();
if (name.endsWith(".url")) {
String poolName = name.substring(0, name.lastIndexOf("."));
String url = props.getProperty(poolName + ".url");
if (url == null) {
log("No URL specified for " + poolName);
continue;
String user = props.getProperty(poolName + ".user");
String password = props.getProperty(poolName + ".password");
String maxconn = props.getProperty(poolName + ".maxconn", "0");
int max;
try {
max = Integer.valueOf(maxconn).intValue();
} catch (NumberFormatException e) {
log("Invalid maxconn value " + maxconn + "for " + poolName);
max = 0;
DBConnectionPool pool = new DBConnectionPool(poolName, url, user, password, max);
pools.put(poolName, pool);
log("Initialized pool " + poolName);
private void init(){
InputStream is = getClass().getResourceAsStream("db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
} catch (Exception e) {
System.err.println("Can't read the properties file. " +
"Make sure db.properties is in the CLASSPATH");
return;
String logFile = dbProps.getProperty("logfile","DBConnectionManager.log");
try {
log = new PrintWriter(new FileWriter(logFile, true), true);
} catch (IOException e) {
System.err.println("Can't open the log file: " + logFile);
log = new PrintWriter(System.err);
loadDrivers(dbProps);
createPools(dbProps);
private void loadDrivers(Properties props) {
String driverClasses = props.getProperty("drivers");
StringTokenizer st = new StringTokenizer(driverClasses);
while (st.hasMoreElements()) {
String driverClassName = st.nextToken().trim();
try {
Driver driver = (Driver) Class.forName(driverClassName).newInstance();
DriverManager.registerDriver(driver);
drivers.addElement(driver);
log("Registered JDBC driver " + driverClassName);
} catch (Exception e) {
log("Can't register JDBC driver: " + driverClassName + ", Exception: " + e);
private void log(String msg) {
log.println(new Date() + ": " + msg);
private void log(Throwable e, String msg) {
log.println(new Date() + ": " + msg);
e.printStackTrace(log);
class DBConnectionPool {
private int checkedOut;
private Vector freeConnections = new Vector();
private int maxConn;
private String name;
private String password;
private String URL;
private String user;
public DBConnectionPool(String name, String URL, String user, String password, int maxConn) {
this.name = name;
this.URL = URL;
this.user = user;
this.password = password;
this.maxConn = maxConn;
public synchronized void freeConnection(Connection con) {
freeConnections.addElement(con);
checkedOut--;
notifyAll();
public synchronized Connection getConnection() {
Connection con = null;
if (freeConnections.size() > 0) {
con = (Connection) freeConnections.firstElement();
freeConnections.removeElementAt(0);
try {
if (con.isClosed()) {
log("Removed bad connection from " + name);
con = getConnection();
} catch (SQLException e) {
log("Removed bad connection from " + name);
con = getConnection();
else if (maxConn == 0 || checkedOut < maxConn) {
con = newConnection();
if (con != null) {
checkedOut++;
return con;
public synchronized Connection getConnection(long timeout) {
long startTime = new Date().getTime();
Connection con;
while ((con = getConnection()) == null) {
try {
wait(timeout);
} catch (InterruptedException e) {}
if ((new Date().getTime() - startTime) >= timeout) {
return null;
return con;
public synchronized void release() {
Enumeration allConnections = freeConnections.elements();
while (allConnections.hasMoreElements()) {
Connection con = (Connection) allConnections.nextElement();
try {
con.close();
log("Closed connection for pool " + name);
} catch (SQLException e) {
log(e, "Can't close connection for pool " + name);
freeConnections.removeAllElements();
private Connection newConnection() {
Connection con = null;
try {
if (user == null) {
con = DriverManager.getConnection(URL);
else {
con = DriverManager.getConnection(URL, user, password);
log("Created a new connection in pool " + name);
} catch (SQLException e) {
log(e, "Can't create a new connection for " + URL);
return null;
return con;

Hi,
static synchronized public DBConnectionManager getInstance() {
The word "synchronized" will allow only one user at a time to access the getInstance() method which returns DBConnectionManager. Suggest u read some stuff on the same
As I am not sure which App server ur using, u cld do the following
1. Create a Conection Pool in ur App Server itself (Weblogic/Websphere/Jboss way)
2. Create a DataSource which maps to this Connection Pool.
3. Use the DataSource object which handles poolong of Connections to access the database
4. As mentioned above, Read notes/documents on "Synchronized" and "Vector" before you use this word in any code of EJB. This will solve ur problem. Read topic called "Collection Framework".
Seetesh

Similar Messages

  • Can I download Photoshop cc more than twice on the same computer

    I had problems with my computer,can I download Photoshop CC more than twice on the same computer?

    Hi problm,
    Yes, you can , it will be counted as second activation if you have not deactivated the previous install & activation.
    I have checked & found that you have deactivated from one machine & it is active on one computer, this entitles you an install.
    Incase it does not help you, please contact adobe http://adobe.ly/yxj0t6
    Regards,
    Rajshree

  • Can a user facetime with more than one user at a time

    I can use facetime with Macbook and connect to another Macbook user on another WIFI network... I was wondering if one can facetime with more than one user at a time?

    ellis911 wrote:
    I can use facetime with Macbook and connect to another Macbook user on another WIFI network... I was wondering if one can facetime with more than one user at a time?
    Only if you have more than one device running FaceTime at your end.
    Mac Pro Quad Core (Early 2009) 2.93Ghz Mac OS X (10.6.5); MacBook Pro (13 inch, Mid 2009) 2.26GHz (10.6.5)
    LED Cinema Display; G4 PowerBook 1.67GHz (10.4.11); iBookSE 366MHz (10.3.9); External iSight; iPod4touch4.2.1

  • Can a single account be logged into more than once at the same time

    -
    Firstly, please excuse me if this has already been asked - I tried searching for various terms but couldn't see anything.
    At present we run a single account (non-admin) on our iMac G5 which holds all out families photos/music/movies etc. I'm wanting to add a MacBook to our iMac. They would communicate either wirelessly, or via an ethernet hub. We would like to fire up the laptop and log into that same account, so all that information is available (read and write) from both computers, and at the same time.
    Is this possible? If so, how is it achieved. Is there some network settings that have to be made on the MacBook?
    I'm aware that there will be limitations - i.e. two people won't be able to modify the same file at the same time. Also that the iMac will have to be powered up for the account to be accessed etc.
    Finally, due to space considerations I'm wanting to move the home folder for our existing account onto an external FW drive (using the techniques I've found in other posts on this forum). Will this affect any solution to my original question?
    Thanks for your time.

    When you turn on file sharing, others can see your computer in the Finder > Go > Network window, where they can click on it to see what shares are available. These can be the public folders (which don't need a password to connect), or user folders (which do). By connecting to one of the shares, they then have access to the files within them. If you don't want to use an external disk, you can use SharePoints to share folders within your account, such as Music or Pictures. Just be aware that sharing files within a user account can run into permissions issues, for example trying to edit a document owned by someone else, which is one of the reasons to use an external disk. Tiger and Leopard also support Access Control Lists, but you need to know what you are doing.

  • How can i prevent a user to login more than once at the same time ?

    Supose there are a user , D .
    and i am using thread and socket in the application.
    once a user logined in , it will open a new socket .
    Well , but D is trying to login twice at the same time ... and my thread is opening two socket for him .... , how can i prevent that ?
    *thanks for help and sorry for my poor english                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Thanks for reply
    ya ~ i've got a solution ~
    actually i am doing a server for mobile phone to get data. Sometime 1 single ID will send twice a message (usually nokXX mobile phones) .. i use milli sec to check those message ....
    n it seems working ....

  • Can you run the Import Wizard more than once at the same time?

    We're going to run the Import Wizard to import content from one BO environment to another.  Can we, at the same time, run the Import Wizard to import different content between those two environments (using the same source and destination both times)?  Obviously we'd have to run the wizard on different workstations.
    Would this cause any issues?  If so, what kind of issues would you expect?
    Thanks,
    Laura

    Yes, this is possible.  The source and destination CMSs treat the requests from the Import Wizard like any other -- increasing the number of active Import Wizard sessions just increases the load on these CMSs.  Before running multiple Import Wizard sessions, be sure there is ample processing power (CPU / memory) to handle the increased load.    and of course, avoid 'touching' the same content in the two sessions in order to avoid unpredictable results.
    -Mike

  • Can I access icloud with more than one Apple ID account on an ipod touch?

    I just bought a new ipod touch and would like to know if I can download past purchases from my fiances Apple ID account using icloud on the ipod touch we are going to share because I am having a problem with being unable to authorize the one macbook computer that we share with both of our accounts. As a solution I was thinking about logging into his account on icloud on our ipod touch and downloading his purchased apps. Will this work?? Thank you so much for reading this I appreciate all and any responses you may leave me.

    You can do that, but if you switch back to the other account, you'll lose everything bought from the first account. We're talking about an iTunes account. You do not want to share the same iCloud account otherwise you both get the same emails, contacts, messages, calendars, etc if you turn those services on for iCloud.

  • Can you video-chat with more than one friend at a time in new Hello?

    Simply wondering if a group of people can video-chat together at same time, or just one-on-one?

    It is currently only possible to have a peer to peer connection with one other computer.
    To connect with multiple computer you would have to connect via a dedicated server and that is currently not possible with WebRTC.

  • I can't open 2 or more HD videos at the same time without having a lag or FPS drop. Chrome does this perfectly, I have 8 Gb RAM and use Win 7 64 bit. Firefox 16

    I watch youtube or different kinds of livestreams in HD a lot. And the last 2-3 month I'm having a problem watching them in Firefox because I get a terrible lag if I open 2 or more tabs with a video inside. As I am typing this message I've had about 5 terrible freezes (I've opened 2 livestreams in my tabs). Sometimes they just crash and I have to restard the page to go on watching, but most of the time they are lagging like they are lacking FPS and it's unwatchable. I tried cleaning the cash and using different versions of Firefox, I tried the new beta (17) and it's the same. My personal opinion is that Shockwave Flash fault, but I reinstalled it and tried different versions so many times, so I don't know what else to do. I like using Firefox, but I can't do it anymore. I tested the same thing in Chrome and it didn't lag a bit even if I open 10 videos at a time.
    My system is:
    Videocard PCI-E 2.0 ZOTAC GeForce GTX 560Ti, ZT-50303-10M, 1Gb, GDDR5
    HDD SEAGATE SV35 ST31000526SV 1Tb SATA III
    Motherboard ASUS P8H61/USB3(3.x) LGA 1155
    DDR3 8 Gb
    CPU INTEL Core i5 2500, LGA 1155
    Windows 7 64 bit
    Firefox 16.0.1

    Hi m1rAcLe,
    try to [https://support.mozilla.org/en-US/kb/troubleshoot-extensions-themes-to-fix-problems#w_turn-off-hardware-acceleration Turn off hardware acceleration] in Firefox and "disable the hardware acceleration" in the Flash Player too :
    http://helpx.adobe.com/flash-player/kb/video-playback-issues.html
    http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html
    also try to [http://kb.mozillazine.org/Flash#Disabling_Protected_Mode_in_Flash_11.3 Disabling Protected Mode in Flash] (the link is for 11.3, do the same for 11.4), see the same in "Last resort" in the next link from adobe forum http://forums.adobe.com/thread/1018071?tstart=0
    thank you

  • How can I access two "E-Business suite" Applications at the same time

    I have Application "A", and for the performance issue, I decide to install another instance let say "B", and clone "B" from "A" in a daily basis, so for some reports I need the user to access "A" and for another reports to access "B".

    On the subsequent invoke event, put up another window.
    Or, duplicate the -app.xml and change the id.

  • Is there a stereo bluetooth headset that can pair with more than one device at a time?

    Is there a stereo bluetooth headset that can pair, i.e. multipoint, with more than one device at a time?
    Are the MacBook and iPhone 4 capable of multipoint bluetooth technoloagy?
    The goal is for my wife to be able to watch her Korean TV soap operas on her MacBook and still receive a call on her iPhone 4 via a stereo bluetooth headset.
    I was looking at the Motorola S10-HD but after further review saw that it only pairs with one device at a time.
    Appreciate any and all input. My Googling has returned no results.
    Rick

    TeslasBB wrote:
    pairing my BB8330 with my blue tooth earphone(TM:jawbone) and my microsoft sync thats in my car simultaneously? if i pair with the car, will i have to pair my jawbone all over again?
    You can only pair one device at a time to your 8330, or any other phone for that matter.  The "pairings" are saved to the phone, you can use one or the other and you won't have to pair it again.  Once you turn your bluetooth device on and the phone is on, they will find each other again.
    Hope this helps,
    John
    Stevie Ray! 1954-1990
    ** Don't forget to resolve your post with the accepted solution.

  • Can I use a magic trackpad with more than one Mac at a time?

    I am attempting to pair a MTP with a second MacBook Pro.  So far I can't get system preferences to find the MTP.
    I am wondering whether the MTP can be paired with only one Mac at a time, and that this is why my MBP won't find it.
    The reason I am thinking this is because the little booklet that comes with the MTP says 'after you pair your MTP with a Mac, you can pair it again with a different Mac.  To do this, you first remove the existing pairing and then pair the trackpad again'.
    Can anyone advise, please?
    If it can be paired with more than one MBP at a time, any suggestions why my system preferences search for the MTP is not producing any results?
    Thanks

    Yes, your keyboard, mouse or trackpad can be paired with multiple Macs.  You can even have multiple keyboards, mice or trackpads paired with one Mac.  The caveat is that the device can only be connected to one Mac at a time.  The device can't be paired or connected with a Mac while it's currently connected to another.
    Pairing a device with 2 Macs will be troublesome if the Macs are located within 33 ft of each other.  The device will connect with the first available paired Mac and then unavailable to the second.   If the Macs are located outside the 10meter range, it's quite easy to power off the keyboard (forcing a disconnect) then walking the keyboard to Mac 2 and powering the keyboard on.   I do this with a keyboard from my iMac to a Mac Mini in another room.
    Captfred

  • Can you sign in with more than one apple id on an iPad?

    Can you sign in with more than one apple id on an iPad?

    Only one account can be signed in at a time (via Settings > Store), and if you turn on automatic downloads and/or download past purchases from an account then you risk tying the iPad to that account for 90 days : http://support.apple.com/kb/HT4627

  • I have iPod shuffle 2nd gen. 1GB, how can I autofill it with more than 70 songs?

    I have iPod shuffle 2nd gen. 1GB, how can I autofill it with more than 70 songs, when I used to be able to get more than l20+ songs?

    Is your shuffle full after the Autofill?  Does the playlist you selected as the source have more than 70 songs?
    My 2nd gen 1GB shuffle currently has 140 songs on it, almost 100% full using Autofill.  The number of songs depends on two factors.  One is the average length of the songs.  Longer songs take more space.  A 20-minute symphony takes more space than a 4-minute pop song.  The other key factor is the bit rate used for compression.
    All of my songs are compressed using the AAC encoder at 256 kbps, which is Apple's current standard and the setting used for downloads from the iTunes Store.  The same songs compressed at 128 kbps AAC takes up half the space.  320 kbps MP3 would use more space per song.  If a lossless format, such as Apple Lossless or AIFF is used to encode, the sound quality is the best possibe, but the file size per song is MUCH higher.
    If you think there is problem on the shuffle, you can try doing a Restore in iTunes.  The Restore button is on the shuffle's Settings tab.  This will erase the shuffle, re-install its software, and set it to default settings. If there is data corruption on the shuffle's storage that is causing this problem, a Restore should fix it.

  • ITunes 8.1 Can't Seem to do More Than One Thing at a Time

    I upgraded to 8.1 and now, rather than a "faster" iTunes experience as was advertised on Apple's website, iTunes can't seem to do more than one thing at a time without locking up the application completely. For instance, when trying to download podcasts if I choose to hit more than one "Get" button at a time iTunes will freeze up until the first podcast has completely downloaded. During this time I cannot access any other screen in iTunes at all.
    This freezing of iTunes also occurred while I was trying to sync my iPhone 3G. I received the Calendar sync error that a few other people have mentioned on the forum and wanted to turn off Calendar sync (since I don't use it and don't understand why iTunes turned it on by default, apparently, after the upgrade) but I had to wait for my iPhone 3G to completely sync before I could gain access to any of the tabs in the iPhone sync window.
    So, basically it seems like the new version of iTunes (8.1) really doesn't like to be bothered while it is trying to copy data from one place to another.
    Any ideas?

    I'm using Vista Ultimate 64-bit and iTunes 8.1 installed OK, but required a restart of the entire OS after upgrading. It takes forever to launch, clicking on certain items (like applications) causes itunes to freeze for about 15-30 seconds before it continues (this is actually something that's been there since the introduction of the app store), I've had to switch my library view to LIST and avoid any sort of album art. Using album art to view my library causes iTunes to be extremely, obnoxiously unresponsive.
    The best part - plugging in my iPhone to sync it... iTunes simply sits there dumbly - doesn't even recognize that I've plugged my iPhone in. So now I can't even sync. QUALITY product, quality. So the app I'm FORCED to use to manage my phone doesn't even work after upgrading. Outstanding.
    I'm terrified of uninstalling and reinstalling... the last time I did that with iTunes it jacked my library up... it "lost" all of my music... basically it disassociated all of the music (even the stuff purchased through the itunes store) with the index file so I had to re-import EVERY song and delete the duplicate entry.
    I searched a ton of forums looking for any clues as to how I could improve performance... All I run into is apple fan boys flaming any and all forums to the point of PC *****, no Apple *****, and so forth. Extremely unhelpful.
    The fact is this - if I wasn't forced to use iTunes to manage my non-jailbroken iPhone 3G, then I'd dump it completely. It is a horrible app. Why punish the customers that haven't gone the route of "jail breaking" their iPhones?
    One individual on one of the forums suggested that blue screens, and all the other random errors, including slow performance were due to a lack of RAM. I have 4GB of RAM on my machine I can run a virtual Fedora core 9 machine and a virtual WinXP machine on my Vista x64 box and still not have any performance issues with those two virtuals in the background sucking up system resources, yet with nothing open and less than 50% of my 4GB of RAM in use iTunes performance is abysmal. I have not run into any other application on my Vista machine that performs as badly as iTunes.
    And Apple is touting a "64-bit" version of iTunes - it isn't. The applications the 64-bit installer installs are all 32-bit.
    So, I'm searching as the two of you are for an answer to horrible performance of iTunes.
    Even exiting out of iTunes takes a day and a half... "saving itunes library".... And my "library" isn't that big.

Maybe you are looking for

  • What's wrong with my code?

    I don't have a lot of time for explanation. Somebody please tell me what's wrong with the following code. import java.nio.*; import java.io.*; public class GettingAnInteger {      public static void main(String args[]) {           IntBuffer intBuf =

  • In need of help to replicate something and then modify it

    I need to recreate an image document that is a bit complex and I need to get some direct feedback regarding how exactly to do this. I'm new to Photoshop. Even though I've watched many of the Photoshop training videos I still need further help for thi

  • AMD Catalyst with Linux Mint

    Dear all, I ahve a Lenovo G10 laptop, which has an AMD RADEON R5 M230 graphic card. I have downloaded the linux drivers  AMD Catalyst for my OS (Linux mint 17.1) from their site but when I start the installation process said that "hardware doesnt sup

  • Add fields to tcode CO12

    Hi all,          As per the client requirement I have to add some columns to the table control in the standard Tcode CO12 (Collective Entry of Confirmations). Is there any way to add columns. Thanks in Advance

  • Ink Signature

    Is it possible to import a signature from a file (like a .tif file) and place it in a .pdf document using Acrobat X? I also use Nitro version 7 and this feature is easily provided and seccurely provided. I understand Digital IDs and do have one but a