Multiple threads calling the same stored proc with different parameters

Hi,
I have a stored procedure which will be called by 8 threads. Every time it takes in a different parameter.
Actual execution time for this proc (irrespective of the parameter) is around 2 seconds. But when I call the 8 threads, I see that the total time taken (END TO END) is around 16 seconds. Threads do acquire a read lock right? Is there a way i can get over this issue?
Please let me know.

Sybase IQ is the database. I am using a thread pool. The time taken to execute this procedure without threads is about 2 seconds. It takes 16 seconds when I start using threads.
I do something like this :
///////////////////////// databaseThreadPool.java
* example of a fixed-size thread pool using the
* executors introduced in Java 5
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class databaseThreadPool
public static void main(String[] args)
* create a thread pool with four threads
ExecutorService execSvc = Executors.newFixedThreadPool( 8);
* place six tasks in the work queue for the thread pool
for( int i = 0; i < 6; i++ )
execSvc.execute( new CountDown() );
     long a =System.currentTimeMillis();
execSvc.execute( new databaseThread("00055","YTD","GROSS") );
execSvc.execute( new databaseThread("00055","YTD","NET") );
execSvc.execute( new databaseThread("00055","YTM","GROSS") );
execSvc.execute( new databaseThread("00055","YTM","NET") );
execSvc.execute( new databaseThread("00055","LY","GROSS") );
execSvc.execute( new databaseThread("00055","LY","NET") );
execSvc.execute( new databaseThread("00055","LLY","GROSS") );
execSvc.execute( new databaseThread("00055","LLY","NET") );
     long b =System.currentTimeMillis();
     try{
     while(databaseThread.done!=8)
          Thread.sleep(1000);
     catch(Exception ex){}
execSvc.shutdown();
System.out.println("END TO END TIME TAKEN : "+(b-a));
/////////////////////////////////////////////////////////// databaseThread.java
import java.io.PrintWriter;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.io.PrintWriter;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.IOException;
public class databaseThread implements Runnable
protected int count = 8;
* the following counter is incremented once
* each time the class is instantiated, giving each
* instance a unique number, which is printed in run()
private static int taskCount = 0;
private final int id = taskCount++;
private String gpNum;
private String time;
private String domain;
public static int i=0;
public static int done=0;
PrintWriter out = null;
Connection connection = null;
Statement statement;
ResultSet rs;
ResultSetMetaData rsmd;
     CallableStatement cStmt = null;
public databaseThread(String gpNum, String time, String domain) {
this.gpNum=gpNum;
this.time=time;
this.domain=domain;
* print the id and the iteration count to the console, then
* yield to another thread.
public void run()
     try
     Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
     connection = DriverManager.getConnection("jdbc:sybase:Tds:XXXXXXXXXXX:XXXXXXX", "cp_dbo","cp_dbo");
     statement = connection.createStatement();
          cStmt=connection.prepareCall("{call XXXXXX ?,?,?)}");
          cStmt.setString(1,gpNum);
          cStmt.setString(2, time);
          cStmt.setString(3,domain);
          long a =System.currentTimeMillis();
          rs=cStmt.executeQuery();
          long b=System.currentTimeMillis();
          System.out.println(id+" Time taken by to execute Query : "+(b-a));
     //rsmd=rs.getMetaData();
          while(rs.next())
          Thread.yield();
     catch (ClassNotFoundException e) {
          System.out.println("Driver Error" );
          e.printStackTrace();
          } catch (SQLException e) {
          System.out.println("SQLException: " + e.getMessage());
}

Similar Messages

  • Can I combine multiple threads from the same contact in iMessage?

    iMessage displays multiple threads for the same contact.  Its very confusing and has resulted in lost messages.  I've tried changing a number of settings but to no avail.  Seems to require everyone in my contact list to eliminate all their email addresses in iMessage.
    Begs the question why does iMessage even need this information?  Worse, why does it suck it into its settings by default.  The directory server should only require a valid Apple ID (associated with the users' devices)  in order to direct an iMessage between two contacts.

    Thanks for the reply, appreciate your input.  I did find another way of doing it and that is to highlight the first e-mail, hold down the shift key and click on the last one.  That highlights them all and then they can all be deleted.  Your ideas also work of course and I thank you for that.  Cheers.

  • I have multiple devices backed up to the same computer each with different data. how do i keep them from syncing all data when i back up or transfer stuff from the computer to a device?

    i have multiple devices backed up to the same computer each with different data. how do i keep them from syncing all data when i back up or transfer stuff from the computer to a device? one is an iphone 6 and the others are ipad mini first gens, each ipad has 64gb and the iphone has 128, need to keep the data seperate as they are not all mine

    Itunes content and pics are NOT part of the backup that itunes performs.
    Backing up, updating, and restoring iPad, iPod touch, and iPhone software
    You should transfer any purchases from iphone regularly:  File>Transfer Purchases  , if they fail to be transferred when you sync.
    You buy one and only one download.  It is your responsibility to move/copy/backup your purchases.
    You can try contacting itunes support and asking for an exception, but they are under no obligation to allow.
    http://www.apple.com/support/itunes

  • HT5114 can i have the same email address with different itunes accounts my kids are to young to have an email address but love apps

    can i have the same email address with different itunes accounts my kids are to young to have an email address but love apps

    Have a look here...
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    And Here  >  Sharing Apps
    http://macmost.com/sharing-ios-apps-with-family.html

  • Can i use 2 ipad's on the same itunes account with different apple accounts?

    Both me and partner have an ipad 4. Though we only have one computer, can we use the same itunes but with different apple acount without any issues? We use some of the same apps, but my partner plays fx Baldus Gate and is worries that save files will be corrupted.

    Each iPad should be linked to its owner's personal, private and nonshared AppleID. In the Mac, each one should have a different login account so each has their own iTunes Library containing your iPad's details. When you use iTunes on the Mac, since each logs in with a different login and corresponding Home directory, iTunes picks up the correct AppleID.

  • How to use the same OC4j server with different port number

    How to use the same OC4j server with different port numbers..?
    I have to OC4J installed on my machine on different hard disk drives....
    I want to be able to run both the server simultaneously..?
    is it possible ..it yes then how..?
    for that i have changed the port number of one server...
    but when i am trying to start the other server with different port number..it says that JVM -Bind already...
    Is there any clues...?
    Nilesh G

    In the config directory:
    default-web-site.xml: Change the port the HTTP listener listens on
    jms.xml: Change the port the JMS service listens on
    rmi.xml: Change the port the ORMI listener listens on.
    Or, you can add another web-site.xml file, and deploy your applications to 1 server, and bind the web applications to the different web sites. This way you only have to deploy your applications to 1 place.
    Rob
    Oracle

  • Ability to process several raw files with the same content but with different exposure into the single picture

    Can you add to the Lightroom an ability to process several raw files with the same content but with different exposure into the single picture?
    Base raw files can be given with exposure bracketing during shooting, for example.
    The goal - to get maximum details in darks and lights (if we use the "ligths recovery" or "fill lights" we lose the quality because raw file just have no all required information).
    The similar (but not the same, only the idea) thing - is High Dynamic Range Photography in Adobe Photoshop
    Thank you

    The plugin LR/Enfuse does this already. And of course Photomatix have a plugin available for Lightroom. This essentially amounts to pixel editing, which is beyond the range of Lightroom's metadata editing.

  • How to download the same song(track) with different keys? iTunes seems to think I have already downloaded the song and will not download the song in a different key of the Demo Track

    How to download the same song(track) with different keys? iTunes seems to think I have already dowloaded the song and will not let me download the song in a different key or the Demo.

    Hello Jigz19,
    It sounds like you are unable to play a couple of songs from your library becuase you get a message that the computer is unauthorized to play, but other content purchased that same day works without issue. I would verify that the affected songs were purchased with the same Apple ID first:
    Recovering a forgotten iTunes Store account name
    http://support.apple.com/kb/ht1920
    Open iTunes
    Highlight one of the items you have purchased (You can find your purchases in your Purchases playlist).
    Choose File > Get Info.
    Click the Summary tab.
    The Account Name area will list the account used to purchase the item. Unless you have changed accounts, this is your iTunes Store account name.
    If so, then delete the songs:
    How to delete content you've downloaded from the iTunes Store, App Store, iBooks Store, or Mac App Store
    http://support.apple.com/kb/HT5772
    Then re download them with this article:
    Download past purchases
    http://support.apple.com/kb/ht2519
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • How is posible to execute in very different periods the same stored proc ?

    Hello,
    I call a store procedure many times on the same session. First 10 executions take place in 30 sec; next calls take 5 sec each.
    This behavior is constant. I think it has to do with the statistics computed by Oracle, but how can I improve first
    executions, too ?
    Thank you,
    Lucian Davitoiu

    It might be.
    Anyway, it is strange that long times are obtained for 10 consecutive executions. Starting with 11st execution, it's period is 6 times shorter. Does it need 10 execs to keep it in memory ?
    On the other hand, this is happening on session level. I mean, I have 2 session; on first session stored procedure executes in 30 secs and, in the same time, on the second session the same stored procedure executes in 5 secs (only because the second session already executed stored procedure 10 times). I think, if procedure would be in memory it will be a global area, and both sessions will execute the proc in the same amount of time, isn't it ?
    Most important is how I might control this behavior ?
    Thank for your ideas,
    Lucian Davitoiu

  • IPhone SDK - Multiple buttons calling the same IBAction

    Hi,
    Can I call the same action with multiple buttons? I´ve just connected
    the action to the buttons in interface builder, but in the header file
    I can´t use - (IBAction)setOperator: (id)sender; as the parameter to the function, it always crash due to uncaught exception. If I use - (IBAction)setOperator; it
    works, but i can´t differentiate wich button was pressed.
    I don´t know if i can set the (id)sender parameter in the interface
    builder. Can anyone help me?
    Thanks,
    Pitteri

    .h file:
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    @interface CalculatorView : UIView {
    IBOutlet UITextField *txtResult;
    IBOutlet UIButton *btnMult;
    IBOutlet UIButton *btnDiv;
    @property (nonatomic, retain) UITextField *txtResult;
    @property (nonatomic, retain) UIButton *btnMult;
    @property (nonatomic, retain) UIButton *btnDiv;
    - (IBAction)setOperator:(id)sender;
    @end
    .m file:
    #import "CalculatorView.h"
    @implementation CalculatorView
    @synthesize btnDiv, btnMult, txtResult;
    - (IBAction)setOperator:(id)sender{
    //if btnMult pressed
    //bla bla bla
    //if btnDiv pressed
    //bla bla bla
    that´s my code. Hope u can help.
    thanks
    @end

  • Multiple threads access the same method.

    Hello,
    I have been trying for a long time to find out multiple threads access the shared data.
    I have written a sample code, there I my intention is that method has to be accessed
    onlny one thread at a time., mean one thread finished the job, then next thread can
    access the shared source. But for this code I am not getting the desired out put what I want. But if I am using synchronized block I am getting the output. Please correct where I got mistake. Please see my code.
    public class TestThread implements Runnable {
         Shared r;
         public TestThread() {
              r = new Shared();
         public static void main(String args[]) {
              Thread t1 = new Thread(new TestThread());
              Thread t2 = new Thread(new TestThread());
              t1.setName("A");
              t2.setName("B");
              t1.start();
              t2.start();
          * (non-Javadoc)
          * @see java.lang.Runnable#run()
         @Override
         public void run() {
              // TODO Auto-generated method stub
              r.count();
    class Shared {
         public synchronized void count() {
              String name = Thread.currentThread().getName();
              System.out.println(name + ":accessed...");
              try {
                   for (int i = 0; i < 5; i++) {
                        System.out.println(name + ": " + i);
              } catch (Exception e) {
                   // TODO: handle exception
    }Thanks
    Bhanu lakshmi.

    It depends on what you synchronize. Non-static methods synchronize on the object, so if you're using several objects, you'll be able to call each from their own thread.
    Make your method synchronized or use only a single object and see the difference.

  • Can multiple threads share the same cursor in berkeley db java edition?

    We use berkeley db to store our path computation results. We now have two threads which need to retrieve records from database. Specifically, the first thread accesses the database from the very beginning and read a certain number of records. Then, the second thread needs to access the database and read the rest records starting from the position where the cursor stops in the first thread. But, now, I cannot let these two threads share the same cursor. So, I have to open the database separately in two threads and use individual cursor for each thread. This means I have to in the second thread let the cursor skip the first certain number of records and then read the rest records. However, in this way, it is a waste of time letting the second thread skip a certain of records. It will be ideal for us that the second thread can start reading the record just from the place where the first thread stops. Actually, I have tried using transactional cursor and wanted to let the two threads share the same transactional cursor. But it seems that this didn't work.
    Can anyone give any suggestion? Thank you so much!
    sgao

    If your question is really about using the BDB Java Edition product please post to the JE forum:
    Berkeley DB Java Edition
    If your question is about using the Java API of the BDB (C-based) product, then this is the correct forum.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem with multiple threads accessing the same Image

    I'm trying to draw into one Image from multiple threads. It works fine for a while, but then suddenly, the image stops updating. Threads are still running but the image won't update. I'm using doublebuffering and threads are simply drawing counters into Image with different speed.
    It seems like the Image gets deadlocked or something. Anyone have any idea what's behind this behavior or perhaps better solution to do such thing.
    Any help will be appreciated.

    Sorry Kglad, I didn't mean to be rude. With "No coding
    errors" I meant the animation itself runs with no errors. I'm sure
    you could run the 20 instances with no freezing (that's why I put
    the post :) ) But I'm affraid it is an animation for a client, so I
    cannot distribute the code.
    Perhaps I didnt explain the situation clearly enough (in part
    because of my poor english...).-
    - By 20 instances I mean 20 separated embedded objects in the
    html
    - The animation is relatively simple. A turned on candle, in
    each cycle I calculate the next position of the flame (that
    oscilates from left to right). The flame is composed by 4
    concentric gradients. There is NO loops, only an 'onEnterFrame'
    function refreshing the flame each time.
    - It's true that I got plenty variables at the _root level.
    If that could be the problem, how can I workaround it?
    - It is my first time trying to embed so many objects at the
    same time too. No idea if the problem could be the way I embed the
    object from the html :(
    - The only thing I can guess is that when a cycle of one of
    the object is running, the other 19 objects must wait their turn.
    That would explain why the more instances I run, the worst results
    I get. In that case, I wonder if there's a way to run them in a
    kind of asynchronous mode, just guessing...
    Any other comment would be appreciated. Anyway, thanks a lot
    everybody for your colaboration.

  • Multiple Threads at the same time

    I am new to threads but what I am attempting to do is start a new thread for each report frequency. Each thread will be on a timer to loop at that frequency. Say, for example, I had reports defined to run at 60, 90, and 1440 minute frequencies. I want to kick off a thread for each of those frequencies. While this code does work, it does not start the next thread until the first one is done. Can I get this loop to spawn threads without caring if the preceeding one is finished or not?
    Here is the code.
    public class Monitor {
    public Monitor() {
    super();
    public static void main(String[] args) throws Exception {
    try {
    ResourceBundle properties = ResourceBundle.getBundle("report");
    String db_driver = properties.getString("DB_DRIVER");
    String db_url = properties.getString("DB_URL");
    String db_user = properties.getString("DB_USERNAME");
    String db_pwd = properties.getString("DB_PASSWORD");
    long freq = 0;
    Class.forName(db_driver);
    String url = db_url;
    Connection con = DriverManager.getConnection(url, db_user, db_pwd);
    EventLog.log("Connection Succeeded");
    String qryString = "select distinct report_freq as report_freq from reportapp";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(qryString);
    ResultSetMetaData rsmd = rs.getMetaData();
    EventLog.log("Query Succeeded");
    boolean moreReports = rs.next();
    while (moreReports) {
    freq = rs.getLong("report_freq");
    new MonitorThread(freq).start();
    moreReports = rs.next();
    rs.close();
    con.close();
    } catch (Exception fatal) {
    EventLog.log("Monitor Exception: " + fatal.getMessage());
    return;
    }//end of main//
    //Thread Code//
    public class MonitorThread extends Thread {
    public MonitorThread(long sleepfor) {
         super();
         run(sleepfor);
    public void run(long sleepfor) {
    try {
    boolean isReportActive = true;
    while (isReportActive) {
    long n = sleepfor * 1000L * 60L;
    //Call class that runs the reports//
    Report.PerformSystemChecks(sleepfor);
    Thread.sleep(n);
    } catch (Exception fatal) {
    EventLog.log("Monitor Exception: " + fatal.getMessage());
    return;
    }

    Here how I would do it... I left few parts open, but you should get the idea.
    abstract class ScheduledThread extends Thread
      long freq, nexttime;
      public ScheduledThread(long freq)
        nextTime=System.currentTimeMillis()+freq;
        this.freq=freq;
      public long getNextTime()
        return nexttime;
      abstract void scheduledRun();
      public void run()
        nextTime+=freq;
        scheduledRun();
    class Scheduler extends Thread
      Vector sceduled=new Vector();
      public synchronized void addSchedule(...)
        scheduled.add(sched);
        notifyAll();
      public long getNextTime()
        // get the lowest time returned from all the sceduled threads
      public void run()
        while (true)
          long nextCall=getNextCall();
          synchronized (this)
            // using wait we can break out of the wait loop if new schedules are added with notify.
            long time=nextCall-System.currentTimeMillis();
            if (time>0)
             this.wait(time);
          // go through all the threads and run those that getNextTime()<System.currentTimeMillis()
    }

  • Multiple threads on the same applet

    hey,
    i want the following functions should be performed by threads
    *background color of my panel should be changed after the given interval,
    *Label of the panel i.e"HELLO USER" should also blink for the given interval
    *the pictures which i have added on that panel should be shown or hide  for the particular time interval.
    basically i want to know how can i use three threads simultaneously on the same panel.

    Have you tried writing code first or just looking for solution simply...
    You can either create anonymus class or, create a seperate class for Thread or, implement Runnable class
    1. Make Blinking text as component which implements Runnable interface.
    2. Make ImageDisplayer as component which implements Runnable interface.
    3. Make a panel which can change colour as another component which can change color, extent JPanel and implement Runnable interface.
    4. For all the three classes put the logic in run method within a loop and add sleep with required interval (Refer java examples).
    5. Add components to Frame/Applet/Panels and create thread object for them.
    6. Start the thread
    Example:
    Thread blinkingThread = new Thread(...object of runnable interface...)
    blinkingThread.start()

Maybe you are looking for

  • How do I Move Events from an Internal to External drive?

    Hello, I am trying to move events on my internal drive to my new external drive. Everything is set up and I see the external drive, but after reading other posts and replies it seems I can't just move the files from the internal to external drive by

  • How to get detail info of application acknowledgement in BPM send step

    Hello in BPM we will send an async message to SAP backend system, we need to know if the message is successfully process or not, if not, we need to get the detail info which is returned in the acknowledgement message. As you know in PI monitor, you c

  • No 3d option in Photoshop CC or CS6

    Hi there, tying to do some 3d text but the 3d button is not there and the 3d drop down menu is all greyed out any ideas? Please Help Adobe Photoshop Version: 14.1.1 (14.1.1 20130910.r.414 2013/09/10:23:00:00) x32 Operating System: Windows 7 64-bit Ve

  • Post iLife 08 install issue with iTunes, need details please for install

    Like others in this discussion area after installing iLife '08 I received the following message after I then tried to open iTunes... "This copy of iTunes is corrupt or is not installed correctly. Please reinstall iTunes." This problem occurred on the

  • Oracle Timesten with oracle apex

    I use Oracle 11gr2 and apex 4.2.4 how can i use oracle timesten with oracle apex? I want to use timesten to improve  performance on report by adding two tables to oracle timsten.