How to run two threads simultaneously ....?

Hello All,
I Am developing an application which send some data to server and from remote place that data is fetched and displayed.
For this i am using Java Servlet as a server which accepts data by readObject() method of object output stream and writes using writeObject() method.
At remote end i am fetching the data and printing that using thread.Data is fetched using URL's method
URL urlServlet = new URL("URL of servlet");
URLConnection con = urlServlet.openConnection();But while fetching it takes some time say 1-2sec because of that my display is not continuous.
I want to write an application such that two threads will be running(in synchronization),second thread will start after few ms of 1st thread.One thread will continuously fetches data and other will display, so that there will be no delay at all while displaying of data.
How to do this?
Thanks In Advance.

Google on: java producer consumer example
Kaj

Similar Messages

  • How to run two thread parallel y on two cores of dual-core ??

    I want to run two threads on two cores ???
    is there any package which support parallel computing??
    can we do this by using java.util.concurrency pakage??
    Thanks you
    please Reply.....

    vikram_p wrote:
    I want to run two threads on two cores ???ok
    Threads are automatically spread over the available cores, as the OS sees fit.
    is there any package which support parallel computing??Java does so without any external libraries.
    can we do this by using java.util.concurrency pakage??yes
    One question mark per question is plenty, thank you.

  • How do i run two threads with different sleep times?

    How do i run two threads with different sleep times?
    Ive got thread A and thread B, they both update a jpanel.
    They both start when i press the start button.
    However thread A updates every 250ms and thread B updates every 1000ms. i cant just run them both at 250ms becuase this will mess it up.
    So for every four runs of thread A i want thread b to only be run once
    Does anyone know how to do this?
    Thanks, Ant...

    ok, ive done it but now i cant stop it!
    ive added buttons to start and stop, the start button works but the stop button doesnt. why doesnt "t.stop();" work?
        public void run() {
            while(t == Thread.currentThread()) {
                System.out.println("No " + t.getName());
                if (t.getName().equals("1")){
                    try {
                        t.sleep(1000); // in milliseconds
                    } catch (InterruptedException e) {}
                } else{
                    try {
                        t.sleep(250); // in milliseconds
                    } catch (InterruptedException e) {}
        }

  • How to run two versions of dreamweaver at the same time

    How to run two versions of any dreamweaver at the same time?
    There must be a way to do this.

    east99 wrote:
    > How to run two versions of any dreamweaver at the same
    time?
    > There must be a way to do this.
    Yes, there is: on two separate computers.
    You cannot run two versions of Dreamweaver simultaneously on
    the same
    computer. They can coexist side by side, but the operating
    system will
    not let you run them together.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • How to run two query  in the same preparedStatement

    Hi all,
    Please tell me how to run two queries in the same preparedStatement object ?
    In my module I have to run two queries and I don't want to make two methods for running two different queries.
    I just want to call this method for both of my queries.
    methodName(long param)
    Connection conn=null;
    PreparedStatement pstmt=null;
    //////////////// some coding
    Please Help !
    Thanks in advance
    amitindia

        public void foo()
            Connection connection = null;
            PreparedStatement stmt = null;
            try {
                connection = ...get from pool...;
                stmt = connection.prepareStatement("...");
                ...fetch results...;
                stmt.close();
                stmt = null; // So the finally statement works if there is an exception
                stmt = connection.prepareStatement("...");
                ...fetch results...;
            } finally {
                if (stmt != null) ..close it...;
                if (connection != null) ..return it to pool...;
        }

  • Does anybody know how to run two independent instances of Calendar simultaneously?

    I've enabled the Debug mode, and have 2 windows open at the same time but can't get them to operate independently. Anybody done this?
    The situation is that I work for a music school that uses iCal to keep track of music lessons for multiple tutors in real time, which sync to relevant tutor's iphones. We've just opened a second premises and would like to use the same system, but be able to monitor everything from either school.
    Debug mode will let me run two instances of Calendar simultaneously, but removing tutors' calendars from one of the Calendar windows removes them from the other.
    Basically I need one Calendar window open for each school, and for them to be independent from each other.
    Any takers?

    How about creating a new "Calendar" with in the same Calendar app?
    Calendar App---> File---> New Calendar
    Name each Calendar for each business location. Example if the original location is on Main St, name that Calendar Main St and the second on Broadway, name that calendar Broadway.
    The other solution could be the same as above, but File---> New Calendar subscription. But I have no idea how that works though.
    KOT

  • How to run two sub vi simultaneously??

    i need to run two sub vi simultaneously in one main vi, becasue it is a must the two sub vi run exactly at the same time, but now i find that if i put they in one diagram ,in fact they are not exactly run at the same time. if you see in high light mode Just like the attached simple example code.  any one can help me to handle this to run the two subvi exactly at  the same time ? how to do it ? thanks so much.
    Attachments:
    how to run subvi simultaneously.vi ‏11 KB

    You are correct, they will not run at exactly the same time.  What is it you are actually trying to do?  What platform are you developing on? What version of LabVIEW? What processor does your target system have? This information is vital in order for us to assist you.  In a nutshell, unless you are running a real-time OS, then the OS you are running is not deterministic.  When you say "at the same time", what are you actually referring to? As a note, when executing parrallel operations in LabVIEW, the execution order may or may not be the same with the highlight bubble on as it is when it is running without highlight execution.  It is highly unlikely that you will be able to just run two sub-vis at the exact same nS.  If you are using DAQ boards, you accomplish this through triggering.  Please give a detailed description of what you are doing, and what you see the road blocks being.
    Thanks
    Paul <--Always Learning!!!
    sense and simplicity.
    Browse my sample VIs?

  • How to run two Automator actions simultaneously?

    I want to perform two actions at once in an automator applcation, specifically Speak Text and Run AppleScript. I can only figure out how to run one after another. Is there a way to have text spoken as a script is run?

    This is what it looks like:

  • How to sync two threads ?

    Hi!
    I've two threads in my app running at the same time. One of them shows some pics in a slideshow, the other plays some background music. How can I sync one of the threads to stop when the other ends ?
    thanks in advance

    I would recomend use listening.methodology: one class is a listener, and the other calls that listening method, which sets some variable which the first thread ckecks regurarily.
    Eg:
    interface StopListener{ public void stop();}
    class A implements StopListener{
    boolean stopped=false;
    public void stop(){stopped=true;}
    public void doSome(){
    while(!stopped){
    //do whatever
    Gil

  • How to run two or more reports in parallel?

    Hi,
    Scenario:
    I have created three report programs. After the first report is processed, I prepare a selection parameter based on the result  and call the other two programs simultaneously by using the SUBMIT command.
    Issue:
    As the other two programs are completely independent, I want the these to run in parallel and return the result set.
    Can anybody suggest how do I achieve this?
    Regards
    s@k

    Dear Radhika,
    Thanks..:)
    To add to the problem, after the first program is processed and I get the result, I prepare a selection parameter table. This
    table I pass to the other two programs as shown:
    Program 2:
      SUBMIT <program_name> AND RETURN
              USER sy-uname
              WITH SELECTION-TABLE lt_params_1.
    Program 3:
      SUBMIT <program_name> AND RETURN
              USER sy-uname
              WITH SELECTION-TABLE lt_params_2.
    As suggested by you, I have checked for the job options. I found that i need to call the function modules in the order as
    1. JOB_OPEN
    2. JOB_SUBMIT
    3. JOB_CLOSE
    The question is how do i pass the selection parameter table in the FM JOB_SUBMIT? I can see there is a report parameter but how do I pass the table to it
    Can you please suggest.
    Regards
    s@k
    Edited by: siemens.a.k on Feb 4, 2010 4:03 PM

  • Cannot run two webcams simultaneously under Mountain Lion

    I am working on  a film project for which I want to record skype calls while I at the same time record the "local" side of the conversation in HD quality with the C910 in the Logitech webcam software. Hence, I want to run two webcams at the same time. The in-built laptop camera in Skype and the C910 in the Logitech Webcam software.
    I have had a lot of difficulties doing thid in Mac OS X. On my old MacBook Pro under OS X 10.6.8. the logitech support recommended initiating the skype conversation with the Isight camera first and only then launching the Logitech software and starting the recording with the C910 cam. That worked fine.
    Now, however I have to do the same on a newer 13" MacBook Pro with OS X 10.8.4. and built in Facetime webcam and it just won`t work. Only one webcam functions at a time. If I launch the Logitech software first, the Facetime camera won´t work in Skype   And when I start a skype conversation first, I only get a black screen (no failure notice whatsoever, the C910 is still detected) in the Logitech Webcam Software.
    I am completely desperate and Logitech product service only told me I should contact apple support. Does anyone know how I can get both webcams running simultaneously?

    I am trying to do something similar...not necessarily with skype but need to connect two webcams (via wifi) and want both feeds displayed simultaneosly on imac.  hoping my reply boosts this thread

  • How to run two icalenders on the same computer?

    How can i run two separate icalenders on the same computer? I have my own icalender with work, home, etc, and it's totally full. I am now running an artists collective and will publish the collectives icalender on the web. I don't, however, want to mix what will be a pretty busy calender with my own already too full one. Is it possible to run two totally separate calenders on the same computer?
    macbook   Mac OS X (10.4.8)  

    trsv,
    Welcome to Apple Discussions.
    Create two Groups...
    Calendar 1:
    Work
    Home
    etc
    Calendar 2:
    Collective Calendar
    You can then switch which groups you wish to display by activating/deactivating the check mark in the Calendar source window.
    That will also allow you to selectively publish the Collective Calendar.
    ;~)

  • How to start two threads at the same time

    Hi there,
      I want to include multithreading in the CVI program. I have two tasks which has no dependence between them, so I would like to start two threads for perform the tasks. I follow the introduction http://www.ni.com/white-paper/3663/en/ to start my code. In my code, I add a command button, when it is pressed, I create two threads to perform the tasks. In each task, I have a big loop and in each iteration, I use ProcessSystemEvents to avoid no response on system message. But it doesn't work actually, the program suspended. I wonder must I initialize the threads in main. I am looking for a way to start the threads in the callback function for a button since I am not starting those threads at the beginning but while it is triggered.
    the main frame of the code looks
    int CVICALLBACK Test1(void *functionData)
    { int i=0;
    for (i = 0; i<100000; i++) {ProcessSystemEvents();}
    return 0;
    int CVICALLBACK Test2(void *functionData)
    int i = 0;
    for (i = 0; i<100000; i++) {ProcessSystemEvents();}
    return 0;
    int CVICALLBACK cmdcb(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
    { int threadID1, threadID2;
    if (event==EVENT_COMMIT)
    SetPanelAttribute(panelHandle, ATTR_DIMMED, 1);
    CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, Test1, NULL, &threadID1);
    CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, Test2, NULL, &threadID2);
    CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, threadID1, 0);
    CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, threadID2, 0);
    return 0;
    Attachments:
    TestThread.zip ‏239 KB

    In my opinion your threads may be simply lasting longer than expected due to an incorrect sleep policy of threads paired with with ProcessSystemEvents () in the loop.
    I made up a quick example that shows this behaviour: playing with "Do not sleep" and "Call ProcessSystemEvents" options you can see how threads execute.
    BTW: do not forget to release the thread function IDs at the end of functions.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?
    Attachments:
    thread.zip ‏7 KB

  • How to run a thread for second time ?

    I have a written a ThreadPool, but I found that basically a thread is not running for the second time. i.e First i call run() method and call stop(). If i call again run() method for the same thread, it is not running. What should I do, If i want to run the thread for the second time ?
    class NewThread implements Runnable {
    String name;
    NewThread(String a) {
    name=a;
    public void run() {
    try{
    for(int i=0;i<5;i++) {
    System.out.println("Thread :" + name + " #" +i);
    Thread.sleep(5);
    catch (Exception e) {
    e.printStackTrace();
    class threadRunnableTest {
    public static void main (String args[]) {
    Runnable runnable=new NewThread("BaSkAr");
    Thread thread = new Thread(runnable);
    try{
    System.out.println("First Thread is starting !!!");
    thread.start();
    Thread.sleep(2000);
    System.out.println("First Thread it to be stopped!!");
    thread.stop();
    System.out.println("Second Thread is starting !!!");
    thread.start();
    Thread.sleep(2000);
    System.out.println("Second Thread it to be stopped!!");
    thread.stop();
    catch (Exception e) {
    e.printStackTrace();

    baskark wrote:
    I have a written a ThreadPool, but I found that basically a thread is not running for the second time. i.e First i call run() method and call stop(). If i call again run() method for the same thread, it is not running. What should I do, If i want to run the thread for the second time ?
    class NewThread implements Runnable {
    String name;
    NewThread(String a) {
    name=a;
    public void run() {
    try{
    for(int i=0;i<5;i++) {
    System.out.println("Thread :" + name + " #" +i);
    Thread.sleep(5);
    catch (Exception e) {
    e.printStackTrace();
    class threadRunnableTest {
    public static void main (String args[]) {
    Runnable runnable=new NewThread("BaSkAr");
    Thread thread = new Thread(runnable);
    try{
    System.out.println("First Thread is starting !!!");
    thread.start();
    Thread.sleep(2000);
    System.out.println("First Thread it to be stopped!!");
    thread.stop();
    System.out.println("Second Thread is starting !!!");
    thread.start();
    Thread.sleep(2000);
    System.out.println("Second Thread it to be stopped!!");
    thread.stop();
    catch (Exception e) {
    e.printStackTrace();
    It's usually helpful to check the documentation:
    [http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#start()|http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#start()]
    start
    public void start()Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
    The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).
    It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.
    So, make a new java.lang.Thread

  • How to run two libraries? [11.0.0]

    Hey everyone. I've been using iTunes for a long time now, as it is a relatively good program for organizing my huge library> I don't use it to listen to music, but I often need to move files around and onto the appropriate devices for my family. Because of this, I got an external hard drive. From time to time, iTunes will forget that my library comes from my external. usually, this is after booting iTunes without having the external plugged in. This can be a nuisance, because iTunes then decides to fill up my laptop's free space with the large amounts of music I put on at once. It gets especially annoying when I need to consolidate files to ensure they are all on the hard drive because it will consolidate to the computer instead.
    My question is, how do I set iTunes up so it will always look for my hard drive and use that as the library first? Then, and only then, if it cannot find my hard drive, it will use my computer's storage. Most important to solving my problem is that during those times it uses my computer's storage, it should automatically use my hard drive if present upon restarting iTunes.
    I have figured out how to have two libraries, but I need to know how to put one on a higher priority and as a default that doesn't get changed.
    To recap, If I run iTunes without my external hard drive, it changes the library location to my computer and does not put the setting back to how it was.

    Aarowaim wrote:
    how do I set iTunes up so it will always look for my hard drive and use that as the library first?
    This is done by default, but it is up to the user to ensure the external or network drive is connected.
    Aarowaim wrote:
    Then, and only then, if it cannot find my hard drive, it will use my computer's storage.
    Again, this is done by default.
    If the user fails to connect the external drive before started iTunes the following steps should be taken.
    Close iTunes.
    Connect drive.
    While holding SHIFT, launch iTunes.
    When prompted to locate or create a new library, select locate and point iTunes to the external drive.
    Is the iTunesLibrary.itl file actually on the external drive or is it on the C drive of the computer?

Maybe you are looking for

  • HT1918 how do i remove my credit card on my iphone?

    i put my credit card in my itunes and i want to remove it but it wont let me i dont have a none botton so how do i remove it because i cant updates app or download free apps because it says there is a problem with my billing information

  • ORDER_PARTNER BAPI_SALESORDER_CREATEFROMDAT2

    Dear everyone,   I tried different approach of filling the order partner parameter for the BAPI_SALESORDER_CREATEFROMDAT2 function. Unfortunately, i encounter the following error: When calling the function module "BAPI_SALESORDER_CREATEFROMDAT2", one

  • Mail is downloading 9000 old messages from March

    Restarting and opening Mail this morning, strangely, Mail is downloading about 9000 (yes, nine thousand) old messages from last March. WHY? I tried clicking on the X to cancel it, thinking it might just be a glitch, but then it started back up again.

  • Doubled list of bookmarks (Word2007 and Adobe Acrobat 8.1.2)

    Our office converts Word documents (doc / docx) from MSWord 2007 (German version) to Adobe PDF by means of Adobe Acrobat version 8.1.2 (German version). The Word documents contain numbered headings which then have to be output within the Bookmark Lis

  • Why don't my iPad & iMac calendars sync by iCloud?

    why don't my iPad & iMac calendars sync by iCloud?