Thread query.

i have the program below. I want to add in the ability to input data from the keyboard and still run the current thread. What do i do? Do i set the current thread as a background thread, then create another thread to handle keyboard input?? How do i get them to run together??
Any tips appreciated.
N.
import java.io.*;
import java.util.*;
public class EmailListener implements Runnable{
     private Thread task = null;
     public EmailListener(){
          if (task == null) {
              task = new Thread(this, "Email");
              task.start();
     public void run() {
          Thread myThread = Thread.currentThread();
         while (task == myThread) {
               try{
                    EmailRetriver er = new EmailRetriver("nemo.compsoc.com","nduggan","christmas",2110,"[email protected]");
                    er.readMail();
                    er.sendMail();
                    er.close();
               catch(Exception e){
                    e.printStackTrace();
                    task = null;
              try {
                        Thread.sleep(10000);
              } catch (Exception e){}
     public static void main (String args[]) throws Exception {
          System.out.println("Intelligent Text Procesor Email Client ");
          new EmailListener();
}

Ah the wonders of concurrent programming. You're probably going to want some resources on it. These things are a bit more involved then you first think. Doug Lea's book is a great place to start. http://java.sun.com/docs/books/cp/ go from there.
-Spinoza

Similar Messages

  • WEB Thread Query

    Hi All,
    The below mentioned query is executing very often.
    it seems to be executing every time a web thread initiates and its degrading the performance.
    Please provide your suggestion why this is being executed very often.
    select a.value lang, b.value terr, c.value cs into :1, :2, :3
    from nls_database_parameters a,
    nls_database_parameters b,
    nls_database_parameters c
    where a.parameter = 'NLS_LANGUAGE'
    and b.parameter = 'NLS_TERRITORY'
    and c.parameter = 'NLS_CHARACTERSET';
    begin
    select owa_util.get_version into :4 from dual;
    exception
    when others then
    :4 := '1.0.0.0.0';
    end;
    begin
    execute immediate 'declare test boolean;
           empty_vc_arr owa_util.vc_arr;
           begin test := owa_match.match_pattern(''test'',empty_vc_arr,empty_vc_arr,false);end;';
    :5 := 1;
    exception
    when others then
    :5 := 0;
    end;
    end;

    It looks like it is trying to test the database for many things FOR EACH PAGE.. (urgh!!)
    Some of those values are going to be mostly static unless a database update is done.
    (eg :4 and :5)
    You could probably cheat and hard code those values and drop the expensive EXECUTE IMMEDIATE code that is doing nothing more then checking that a particular function exists.
    Also, for that first SQL statement, try adding the /*+ cache */ hint.
    You may need to use the OCI drivers for it to work.
    MK

  • Core i5 'max thread' query

    Hi guys,
    I've just upgraded my MacBook Pro to a unibody Core i5 model. Loving the speed increase all round in Motion & FCP etc.
    Although it's a dual core (2.4), due to the hyper-threading on each core, it registers in Compressor and Shake as having 4 accessible processing threads.
    So my question, perhaps obvious as it may sound, is: Should I enable Shake & Compressor to use all 4 threads, or should I cap them to 2?
    Only reason I ask is because I'm rendering a project in Shake at the min with 'Max Thread' set to 4, yet it seems really slow. Perhaps it's an abnormally large project? Although it only contains 1 x ProRess 422LT video and one Quicktime SD file. The rest is a concoction of keying nodes and adjustment layers etc.
    I've included a screen grab of the project in question (not sure if it helps at all):
    http://i1.creativecow.net/u/134316/shakerenderscreen.jpg
    It's a bit of a messy project, but the original screen & lighting were quite poor, so I've had to work hard to get it to viewable state I am by no means, a shake-spert
    All help & advice appreciated.
    Thanks in advance.
    Chaz

    What I was told and seems to hold true for me is to use one instance for two processors, so for 4 processes (virtual or otherwise), use two instances...
    Patrick

  • Problem of Query of Module Purchase Order, Good Receipt PO, Good Return

    Hi,
    I would like to seek for assistance regarding double entries of documents,  I have used the query and found out lately the it has a problem, Please refer to thread "Query of Module Purchase Order, Good Receipt PO, Good Return" for details.
    You help is very much appreciated.
    Regards,
    Clint

    Hi Clint,
    Try this one:
    SELECT DISTINCT 'GRPO' AS TYPE, T1.DOCNUM
    'GRPO/RET#', T3.DOCNUM 'PO#',T1.CARDCODE,
    T1.CARDNAME , T1.DOCDATE, T0.ITEMCODE, T0.QUANTITY,
    T0.PRICE, T0.LINETOTAL
    FROM DBO.PDN1 T0
    INNER JOIN DBO.OPDN T1 ON T1.DOCENTRY = T0.DOCENTRY
    LEFT JOIN DBO.POR1 T2 ON T0.BASEENTRY = T2.DOCENTRY
    INNER JOIN DBO.OPOR T3 ON T2.DOCENTRY = T3.DOCENTRY
    WHERE T1.DOCNUM = '[%0]' AND T0.ITEMCODE IS NOT NULL
    UNION ALL
    SELECT DISTINCT 'RETR', T1.DOCNUM,T3.DOCNUM,
    T1.CARDCODE, T1.CARDNAME , T1.DOCDATE, T0.ITEMCODE,
    T0.QUANTITY, T0.PRICE, T0.LINETOTAL
    FROM PDN1 T0
    INNER JOIN OPDN T1 ON T1.DOCENTRY = T0.DOCENTRY
    LEFT JOIN RPD1 T2 ON T0.TRGETENTRY = T2.DOCENTRY
    INNER JOIN ORPD T3 ON T2.DOCENTRY = T3.DOCENTRY
    WHERE T1.DOCNUM = '[%0]' AND T0.ITEMCODE IS NOT NULL
    If you still have duplicates, let me know any differences in those lines.
    Thanks,
    Gordon

  • Query based on date partition

    Hi,
    I am trying to output only a successful job during the past 24 hrs of each day. If there is job that has an outcome of a success and a failure within the last
    24 hrs for each day, I want to only output the successful one. If there are no success for the same job, I will output the last attempted failed job.
    Here are my columns:
    current output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3400907     7/27/2012 10:01:09 AM     polA     target1          Failed          0     incr     clone1
    3389180     7/23/2012 10:01:14 AM     polA     target1          Failed          1     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3367074     7/22/2012 11:24:00 AM     polA     target1          Failed          1     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    336074     7/21/2012 10:01:08 AM     polA     target1          Success          0     incr     clone1
    desired output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    Here is a code I am trying to use without success:
    select *
    from
       (selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
              ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn
                   from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
       where rn = 1
       order by jobdate desc;Thanks,
    -Abe

    Hi, Abe,
    You're on the right track, using ROW_NUMBER to assign numbers, and picking only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
    You want to assign a #1 for each distinct combination of group_id, path, asset and calendar day , right?
    Then you need to PARTITION BY group_id, path, asset and calendar day . I think you realized that when you named this thread "Query Based *on date partition* ".
    The next thing is the analytic ORDER BY clause. To see which row in each partition gets assigned #1, you need to order the rows by outcome ('Success' first, then 'Failed'), and after that, by jobdate (latest jobdate first, which is DESCending order).
    If so, this is what you want:
    WITH     got_r_num     AS
         SELECT  j.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER ( PARTITION BY  group_id     -- GROUP is not a good column name
                                   ,                    path
                             ,             asset
                             ,             TRUNC (jobdate)
                                   ORDER BY          CASE  outcome
                                                 WHEN  'Succcess'
                                         THEN  1
                                         ELSE  2
                                             END 
                             ,             jobdate     DESC
                           )      AS r_num
         FROM    job_table  j
         WHERE     outcome     IN ('Success', 'Failed')
    --     AND     ...     -- Any other filtering, if needed
    SELECT     *       -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test it.
    It looks like you posted multiple copies of this thread.  I'll bet that's not your fault; this site can cause that.  Even though it's not your fault, please mark all the duplicate versions of this thread as "Answered" right away, and continue in this thread if necessary.
    Edited by: Frank Kulash on Jul 28, 2012 11:47 PM
    This site is flakier than I thought! I did see at least 3 copies of this same thread earlier, but I don't see them now.

  • Simple select query is taking a lot of time

    hi gems...
    my table has 7267563 rows...and i am doing a simple select * from table;
    but it is taking a lot of time nearly 25minutes but not completed...
    when i did select count(1) from table then it gave the result instantly also select * from table where rownum < 10 is also fine...even when i am selecting all the records using rownum i.e. select * from table where rownum < 7267563 is also giving result instantly...
    but the entire table is not getting result i.e. select * from table...also there is no lock in the table(though i know that select is nothing to do with lock)..
    what may be the issue..please suggest...thanks in advance...
    Edited by: user12780416 on Dec 12, 2011 11:08 PM

    Hi;
    Please see below thread
    query takes too long ...
    help in solving long run query
    HOW TO: Post a SQL statement tuning request - template posting
    Hope it helps
    Regard
    Helios

  • Timing Query Performance in Java

    Hello again everyone,
    I had previously asked a question concerning timing the execution time of an individual thread, and I have been unable to uncover an acceptable answer. So, instead of threads I may use system processes. Some background...
    I am writing a database load-testing application that simulates load via. submitting a set of queries through multiple connections. These multiple connections can be separate threads or processes that run concurrently in order to get a feel for how the database performs under the load of a number of users. My question is does anyone know how to get the actual execution time of a single process. I am afraid that due to the large number of users, the system will be unacceptably slow. Normally I could do something like this ...
    long start = System.getcurrentTimeMillis();
    executeJDBCquery();
    end = System.getcurrentTimeMillis() - start;
    however I am concerned that with a large number of users this will not provide an accurate query execution time since the system will be distrubting its processing power over so many processes. The first suggestion that has raised is to get the query processing time from the RDBMS, however, I can't figure out how this can be done with Oracle 8i. Is there a hidden JDBC method or property that will give server-side execution time for a query, or can anyone suggest a solution that will work with oracle? If anyone knows how to get the actual execution time of a single system process that would be very helpful as well. Thanks for any help that you may be able to give, let me know if I can provide any more details.
    Dan

    Try this:
    Create a new table in Oracle to track the times, such as:
    Create Table time_log (Thread_ID number, Query_ID number,
    start_time number, end_time number);
    On the tables that you are performing the queries on, create before and after statement-level triggers. These triggers would insert a record into the time_log field as required (i.e., the before trigger enters a start time, the after trigger enters an end time).
    To properly keep track of the execution times, you would need a thread_id (possibly pass this as part of the query call) and a table/query_id. This way you would know which thread queried what table.
    For your final timing computations, simply query the time_log table, making the correct calculations.
    One note: the start and end times are numbers, not dates, as the Oracle dates only get down to seconds. You will have to use the DBMS_UTILITY.GET_TIME, which returns the current time in hundreds of a second.
    HTH,
    Sean

  • Query taking longtime to run

    Hi Gurus,
    We have created a query on a InfoCube and when I run it in query designer its taking long time to get the results and final report.
    How can I optimize the performance ? Please let me know what would be the measures for optimizing query performance.
    Thanks in advance,
    sudhakar.

    Hi,
    Query performance can be tuned once you have an idea of its potential usage pattern.
    Starting from query properties (Read mode - very important setting, and cache settings) to drill down pattern, everything matters.
    On DB level (your data model - Cube/Aggregate/Indices) can impact the query performance. Some help can be had by using turning on DB statistics.
    On OLAP level - your olap level processing (conditions/exceptions/virtualKF/Char/Variable processing/Global cache etc) adds to the performance overhead and you can finetune these to improve query performance.
    On GUI level - Definition of query (too much data will load the network) may impact the performance. In addition (this is from Teched session I attended), Excel has more overhead on GUI level as compared to http, and so at times, using a wb based report may perform better than excel based queries.
    In addition, you can think of pre-calculated web templates to provide faster reports to users (if drill-down is not required). Also, some other techniques (eg if a report is executed many times and is resource intensive, you can schedule this report once after the data refresh and keep its global cache on, so this report is available in the main memory and every subsequent execution will fetch it from OLAP itself and will be much faster).
    In addition to RSRT, ST05 (sql trace), SE30 (runtime analysis) and system statistics (ST03) may help you in identifying performance issues with a report.
    Also check this thread:
    Query BW tahckes too much time to runn
    Regards
    Lavanya

  • Pro*c db disconnect error on multiple threads

    Running multiple users in separate threads results in sporadic errors on disconnecting from the database in a pro*c application running on redhat and an oracle 10g 10.2.0.4.0 db. When the error occurs, it coincides with two threads querying the database concurrently. Either both threads report an error or one. If both, they report different errors: first ORA-01403 (no data found) then ORA-01012 (not logged on). If only one, only ORA-01403 is reported. The same or different pro*c routines (which call stored procs) may be involved. As it occurs on concurrent threads, i tried modifying the code to disconnect twice from one call, but that returns a different error (SQL-02134: Invalid runtime context). Any idea what could be happening?

    i have some more information on this issue. An error (non-zero sqlca.sqlcode) is returned after this line:
    EXEC SQL COMMIT WORK RELEASE;
    These are queries, so i don't think there is a problem with the commit. (They are stored procs. Even if there was a db update somewhere, why would commit return an error? It doesn't appear to timeout as it happens in millisecs.) Why would an error be returned on the disconnect (RELEASE)?
    If this is the wrong forum, could anyone suggest a better one? I didn't find anything really appropriate.
    Thanks in advance!

  • Golden Arrow In Query

    How to get Golden Arrow In Query for a particular field
    Regards
    Pawan

    Hi Pawan,
    Check the Thread
    query with linked button (arrow)
    Orange Arrow in a query
    *Close the thread if issue solved.
    Regards
    Jambulingam.P

  • How to find who has deleted the query in Production system

    I Experts,
    I have an issue. Someone has deleted one query in Production system.
    How can i find who has deleted the query??
    I searched the ans for the same i the below threads :-
    Query deleted in production
    How to find out who has deleted the production Query
    But it didn't help me as i couldn't understand how to use the transaction SLG1.. Can Someone please explain me how can i find out who has deleted the Query..
    Regards,
    Pavan Raj

    Hello,
    Please, remember the date on which date the query has seen last time  in the production server. You can use the last date in the From date and To date would be current  date and execute the SLG1 tcode. It would list you all the logs in the Object text you can search for BEX Query designer and sub object text column you can check for delete logs options.
    Double click on the object will list you the query and name. From the user column you can find who has deleted the query.
    Might be this can help you for analysis.
    Thanks
    Geeta Sharma

  • How to get the Thread in another running application??

    Hi,
    If I have a java application running (as daemon), how can I get the running thread context from another new started java application?
    What I'm trying to accomplish here is that, after I started a daemon thread ( a ServerSocket program ), I want to write another program to control the running thread ( query the status, stop it, or restart it ...).
    Any help will be highly appreciated! Thanks.

    A different java application runs in a different Processand they cannot share anything.
    Any lucky out there? Anyone tried something on this?

  • Using Enter-Query Mode Programmatically

    A question was raised in an earlier thread
    QUERY CRITERIA MANAGER
    about how to use Enter-Query mode programmatically in a way that doesn't stop
    and prompt the user to enter a query after switching from Normal mode to Enter-Query mode.
    Since the solution may not be widely known, I thought I'd demonstrate the technique here in a new thread.
    Create a simple form with just two blocks. Using the data block wizard, create an EMP block with one
    text item for ENAME. Place it on the canvas. Create the other block as a control block and name it CONTROL.
    Inside the control block create the following items:
    - create a text item named TXT_BOX
    (The user will enter their search pattern criteria in this text box while in Normal mode.)
    - create a push button item named EXECUTE_QUERY
    (This button will switch to Enter-Query mode, execute the query, then return to Normal mode.)
    Place both control items on the canvas.
    Inside the WHEN-BUTTON-PRESSED trigger for the EXECUTE_QUERY button, enter the following code:
    DECLARE
         timer_id TIMER;
    BEGIN
         :GLOBAL.search_criteria := :CONTROL.TXT_BOX;
         GO_BLOCK('EMP');
         timer_id := CREATE_TIMER('ENT_QRY', 1500, NO_REPEAT);
         -- 1500 may be a little long, but provides a margin of error
         ENTER_QUERY;
    END;
    Next, create a WHEN-TIMER-EXPIRED trigger at the form level. Inside this trigger enter the following code:
    If GET_APPLICATION_PROPERTY(TIMER_NAME) = 'ENT_QRY' THEN
         :EMP.ENAME := :GLOBAL.search_criteria;
         EXECUTE_QUERY;
         IF :SYSTEM.MODE = 'ENTER-QUERY' THEN
              EXIT_FORM; -- return to Normal mode
         END IF;
    END IF;
    GO_ITEM('CONTROL.TXT_BOX');
    Now, when the user runs the form and logs into the SCOTT schema, he enters a search criteria
    such as A% in the TXT_BOX while in Normal mode. Then clicks the EXECUTE_QUERY button.
    The form will switch to Enter-Query mode, retrieve all names in ENAME that begin with the letter A,
    and then return to Normal mode without pausing for the user to enter a search criteria.
    If the query should happen to fail, the form displays the error:
    "FRM-40301: Query caused no records to be retrieved. Re-enter."
    then switches automatically back to Normal mode so the user can try entering a new criteria.

    I'm showing how to do it when switching modes. I'm
    not suggesting this is the best way to do a query.We need to look at this in the context of the original probelm in the thread linked to above. For most cases the when-timer-expired etc is just a huge detour around using the pre-query trigger but it's an interesting approach to the specific problem in the earlier thread. The OP there wanted to be able to type '>5000' into a number field in a non-database block, which we can do in a database block in enter-query mode, and use it as a query parameter in the database block. Perhaps if we enter this into a character field in the non-database block and populate the numeric field in the database block whilst in enter-query mode then we can do searches on ranges of data? Unfortunately it doesn't work - you get an ora-06502 error just like you do when using the pre-query trigger. For the situation in the original thread you would have to use a 'default where'.

  • Assigning a Query to a Function key

    Hi,
    Is it possible to assign a query to a shortcut key or function key?
    I can't see that this is possible
    thanks
    Mark

    Hi
    Please take a look at this thread
    Query to Menu
    This will solve your problem
    Thank you
    Bishal

  • Parallell query performance

    Hi Experts,
    I could not find any reference with regards to performance of parallel query when the SMT(simultaneous multi-thread) enabled on AIX. Could you please share your thoughts based on experience?

    What are you asking to compare?  The performance of parallel query on AIX vs the performance of a single-threaded query?  The performance of parallel query on AIX with SMT enabled vs. the performance of parallel query on AIX with SMT disabled?  Something else?
    Realistically, any sort of discussion about performance will be highly dependent on the specifics of your query/ queries and the load characteristics of your system.  It is entirely possible for parallel query to make a single-threaded query slower.  It is entirely possible for parallel query to allow a single poorly-performing query to consume all the available resources on the system and to make every other session grind to a halt.  It is entirely possible for parallel query to create large improvements in the performance of a query and of a system.  Without knowing your queries, your workload, your system, your configuration, etc it is impossible to guess what would happen on your system.  That is even more true when we're talking about tweaking operating system configuration knowing nothing about your database.
    Justin

Maybe you are looking for

  • Black stroke around image in Web Export

    More specifically, I'm using the LightRoom Flash Gallery selection as that provides just the structure that I want/need. To match my website (still in construction) I've altered the colors in LightRoom's controls. Separately, I've added a frame aroun

  • Lightroom 1.4.1

    Lightroom 1.4.1 refuses to tranfer files from either of my cameras which has not happened before. It only tranfers the first few files in to Lightroom and then seems to stall. Lightroom continues to accept and download images from my memory sticks bu

  • Starting oracle weblogic server as windows Service

    hi dear friends, i am working with oracle Weblogic server 10.3 and oracle Jdeveloper 11g i have an Ear file and deployed it on weblogic server and that work truly now,i want to start my server with windows Services for this goal i read some of the do

  • How do I delete photos from the photostream on Iphoto?

    My photostream on Iphoto won't let me delete pictures. I have already deleted the photos from the photostream on my iphone and even deleted the photos from the Iphoto library. Those photos still show up on the photostream, and I really want them gpne

  • Which abap statements will start new internal session in the same external

    hi which abap statements will start new internal session in the same external