Basic query in JAVA Threads....Please reply !!

I have a class (say ABC) which extends Thread...This class basically
reads some file which provides some start-time and stop-time information..
File structure is like:-
===========================================
<Entry1>Starttime = A and Stoptime = B
===========================================
Logic is that thread sleeps till time A arrived, then do some operations (which are written
in it's run() method) till stoptime..
The object of ABC class is being constructed in some other class.
Now there is a change....File can have multiple entries like..
======================================
<Entry1>starttime = A and stoptime = B
<Entry2>starttime = X and stoptime = Z
<Entry3>starttime = A and stoptime = B
<Entryn>starttime = X and stoptime = Z
======================================
The start-time and stop-time of any two Entries can be same or different.
The operations should start executing at the defined time..
In this case, multiple threads are required, which can do the operations
mentioned in Entry1,2 etc.....But how should it be implemented..
My query is:-
1) Can I have a common-wrapper class, which reads the file and based on
the number of Entries, instantiates that much number of threads...
But how to do that....I am new to JAVA...Should that class be a simple
class...or should it also implement Thread/Runnable interface.....
Or can I implement it as ThreadGroup......
Please give soem suggestions....Thanks...

e.g.
        ScheduledExecutorService exec = Executors.newScheduledThreadPool(2);
        exec.schedule(new Runnable() {
            public void run() {
                runTask();
        }, delay, TimeUnit.MILLISECONDS);

Similar Messages

  • Java Trick - Please Reply Urgently

    how can i break this user input into different emails. Note user can give any number of mails.
    [email protected]@[email protected]@yahoo.com
    suppose user entered these how can i convert this line in to this.
    [email protected]
    [email protected]
    [email protected]
    [email protected]

    If this is a generalized situation - ie, email from anyone at any location on the Internet, there is no way. There is nothing that will separate the end of one address from the beginning of the following "name".
    Consider that Internet addresses can end in 2 letters (country), 3 letters (domain), maybe more? "Names" can be uppercase, lowercase, symbols, etc. If you can restrict the variation a solution may be possible.
    Best bet is to insert a delimiter between entries at creation, then parse using that delimiter.

  • Java (JMX) vs WLST (Please Reply.. Its Urgent!)

    HI,
    I know that there are two ways to admin weblogic server. One way is by WLST scripts which we write in WLST console. Second way is by JMX which we write in JAVA language.
    I know that java language gives more flexibility but still all the scripts present in my companies Weblogic servers are WLST scripts.
    Can anyone tell me about all the benefits and advantages I can have if I change them to Java (JMX) code.
    One of the Flexibility is that I can implement multithreading and start multiple AdminServer (in multiple domain) at same time.
    Thanks
    Nitish Kumar

    Doublepost: http://forum.java.sun.com/thread.jspa?threadID=5192841
    Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5192927
    Like I said in your former topic: just debug it. Run the debugger or put some simple System.out.println() lines to check if the array has a length, if the array elements are not null, if the final SQL statement is correct, etcetera.
    By the way, with putting pressure by shouting "please reply its urgent" you don't gain that much respect from our side. Some will refuse to reply. Urgency is your issue, not ours.

  • Please reply to this basic question....

    i am using java version 1.4.1
    In java home directory it contains bin and jre forlders.
    In both of the folders java.exe file is there.
    What is the use of having the same file in both directiory......
    Please reply to this basic question....

    One probaly came with the JDK, and one came with the complete JRE that's included in the JDK...

  • A Lot of Question: PLEASE REPLY TO THIS THREAD

    Hi, I am a 16 year old teen that is about to wait for the right moment to have my dream of starting a youtube channel. Ive done a lot of research comparing how any type of laptop will compare when I record and play my games, because i mostly want to get into gaming youtube channel. Although i might want to do just gaming ive also wanted to do videos of unboxing and music covers. My friend that knows a lot about computers told me that i should get a mac if i want to do mainly editing, or if i want to just game and record i should buy a pc laptop. He recommended that i should buy a laptop from IBUYPOWER that has better specs than that of the mac book pro retina 15" and is cheaper. That moves onto my next question asking why are macs so overpriced? I did all my research on that too, and it most likely seems it is almost a brand name expense like louis vuotton. Next question is, how is the cheapest way I can get the 15" retina mac book pro for the cheapest price possible, should i wait until black friday for sales to lower, or should i wait until the next year to get the next 2015 model. Is the newer progressing years of MacBook pros that much better that i should wait until the next year to get it. Next question, say i wanted to play a game that is only on windows platform, ex. Skyrim. Should i play a cracked version that has been reformatted to the mac, or should i just download windows on my mac so that i can play it with more ease of use that way, instead of having to use everything in the mac side when it was originally formatted for Windows. Anyway thank you for your time, and even if you dont know the answer to these questions, PLEASE ANSWER ANYWAY, THANK YOU!
    MacBook Pro with Retina display, PLEASE REPLY TO THIS THREAD

    yellowfelow wrote:
    That moves onto my next question asking why are macs so overpriced?
    There is no such thing as overpriced. Apple is the most profitable company in the world. It sells all of the Macs it makes - every single one. Not everyone can afford a Mac, but such is life.
    I did all my research on that too, and it most likely seems it is almost a brand name expense like louis vuotton.
    That is incorrect. According to Forbes, Apple is the #1 most valuable brand, while Louis Vuitton is #10.
    Next question is, how is the cheapest way I can get the 15" retina mac book pro for the cheapest price possible, should i wait until black friday for sales to lower, or should i wait until the next year to get the next 2015 model.
    Machines may get more powerful every year, but they never get cheaper. You may be able to save more money the longer you wait. If you can't afford a 15" retina, consider a refurbished unit (buy directly from Apple only - see babowa's link), a 13" model, or an Air.
    Is the newer progressing years of MacBook pros that much better that i should wait until the next year to get it.
    They get better every year. If you wait forever, then the machine you never buy will be infinitely powerful.
    Next question, say i wanted to play a game that is only on windows platform, ex. Skyrim. Should i play a cracked version that has been reformatted to the mac, or should i just download windows on my mac so that i can play it with more ease of use that way, instead of having to use everything in the mac side when it was originally formatted for Windows.
    There is no such think as a "cracked version that has been reformatted to the Mac". If you want to run Windows software, buy a PC and run Windows. Most people do. You may be able to play that game on a Mac using Bootcamp, but it isn't guaranteed.

  • All who replied to my earlier questions please reply to this  thread ?

    hi, i have posted many questions and got them answered correctly. The members who replied to my questions posted previously,please reply to this post as "hi" or even an empty message. I want to add as many dukestars as possible for them. I am so sorry that i havent even responded or thanked anyone who provided the correct answers or replied to my post. So atleast let me add some duke stars for you. I remember the members who replied me. Thank you so much.Please provide me an opportunity to serve you.
    Thank You

    Your 23 posts are all here: [~suryakiran_s]. Award them there.

  • Please reply:how to avoid extra trailing spaces while using cursor sharing

    i am using cursor sharing with FORCE or SIMILAR.
    what is the solution to avoid extra trailing spaces without any java code change.
    do we have any option in oracle to avoid extra trailing spaces during the query processing ?
    I am using Oracle 10g
    CURSOR SHARING is a feature in which multiple sql statements
    which are same will have a shared cursor (in the library cache) for an oracle session,
    i.e, the first three steps of the sql processing (hard parse, soft parse, optimization)
    will be done only the first time that kind of statement is executed.
    There are two ways in which similar SQL statements with different condition values can be made to "SHARE" cursor during execution:
    1. Writing SQLs with Bind Variables: SQLs having no hard coded literals in them
    For e.g., the query below
    SELECT node.emp_name AS configid
    FROM emp node
    WHERE emp_no = :1
    AND dept_no =
    DECODE (SUBSTR (:2, 1, 3),
    :3, :4,
    (SELECT MAX (dept_no)
    FROM emp
    WHERE emp_no = :5 AND dept_no <= :6)
    AND node.dept_type = :7
    ORDER BY node.emp_name
    Here all the variables are dynamically bound during the execution. The ":X" represents BIND Variable and the actual values are bound to the SQL only at the 4th step of the execution of the SQL.
    In applications: The queries written with "?" as bind variables will be converted into ":X" and are sqls with Bind Variables.
    2. The CURSOR_SHARING parameter: Only Useful for SQL statements containing literals:
    For eg., the query below:
    SELECT node.emp_name AS configid
    FROM emp node
    WHERE emp_no = 'H200'
    AND dept_no =
    DECODE (SUBSTR (:1, 1, 3),
    'PLN', :2,
    (SELECT MAX (dept_no)
    FROM emp
    WHERE emp_no = :3 AND dept_no <= :4)
    AND node.dept_type = :5
    ORDER BY node.emp_name
    In the query above, there are two hard coded literals H200 , PLN. In this case when the same SQL executed with different values like (H2003 , PLN), oracle will create a new cursor for this statement and all the first three steps ( hard & soft parse and optimization plan) needs to be done again.
    This can be avoided by changing the CURSOR_SHARING parameter which can be set to any of three values:
    1. EXACT: Causes the mechanism not be used, i.e. no cursor sharing for statements with different literals. This is the default value.
    2. FORCE: Causes unconditional sharing of SQL statements that only differ in literals.
    3. SIMILAR: Causes cursor sharing to take place when this is known not to have any impact on optimization.
    So, FORCE and SIMILAR values of the parameter will be helping in cursor sharing and improve the performance of the SQLs having literals.
    But here the problem arises if we use the FORCE and SIMILAR other than EXACT.
    alter session set cursor_sharing ='EXACT'
    select 1 from dual;
    '1'
    1
    alter session set curson_sharing='FORCE'
    select 2 from dual;
    '2'
    2
    alter session set curson_sharing='SIMILAR'
    select 3 from dual;
    '3'
    3
    So, this will give extra trailing spaces in when we retrieve from java method and any
    further java processing based on the hardcoded literal values will fail. this needs lot of
    effort in remodifying the existing millions of lines of code.
    My question is i have to use cursor sharing with FORCE or SIMILAR and can't we do the trimming
    from the oracle query processing level ?
    please help me on this ?
    Message was edited by:
    Leeladhar
    Message was edited by:
    Leeladhar

    Please reply to this thread
    How to avoid extr trailing spaces using Cursor sharing opton FORCE, SIMILAR

  • Basic query in Oracle Spatial

    I'm trying to learn Oracle Spatial working with 11g R2 and with 3D georeferenced data (specifically data describing buildings in a city).
    But I'm having trouble getting a basic query to work on my dataset (it works for the book example), and I'm trying to do it exactly the way it's done in the Spatial Developer's Guide for 11g.
    To learn how spatial queries work, I set up the cola_markets tables used in the book, made the appropriate manual entry in the user_sdo_geom_metadata view and created the index. Having done that, I can run the following simple query (as well as the others in the manual) on the book tables:
    SELECT SDO_GEOM.SDO_DISTANCE(c_b.shape, c_d.shape, 0.005)
    FROM cola_markets c_b, cola_markets c_d
    WHERE c_b.name = 'cola_b' AND c_d.name = 'cola_d';
    but when I try to do the same thing on my own tables (created from citygml data), I get an error. There is the difference that the data is 3D, and the index was created without any PARAMETERS ( ... ), hence is just 2D. But still I don't get why the following query doesn't work:
    SELECT SDO_GEOM.SDO_DISTANCE(c_w.envelope, c_b.envelope, 0.0005)
    FROM cityobject c_w,
         cityobject c_b
    WHERE c_w.id = 50025
         AND c_b.id = 50018;
    The id's for the buildings are valid, and I used the same tolerance used by the software that set up the database.
    Here's the error I get in SQL developer:
    ORA-29532: Java call terminated by uncaught Java exception: java.lang.Exception: 54535
    ORA-06512: at "MDSYS.SDO_3GL", line 637
    ORA-06512: at "MDSYS.SDO_GEOM", line 1973
    ORA-06512: at "MDSYS.SDO_GEOM", line 1990
    29532. 00000 - "Java call terminated by uncaught Java exception: %s"
    *Cause: A Java exception or error was signaled and could not be
         resolved by the Java code.
    *Action: Modify Java code, if this behavior is not intended.
    So, thinking it might have something to do with the fact that it's a Java interface, I also tried running it from SQL/PL command line and get essentially the same thing:
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.Exception: 54535
    ORA-06512: at "MDSYS.SDO_3GL", line 637
    ORA-06512: at "MDSYS.SDO_GEOM", line 1973
    ORA-06512: at "MDSYS.SDO_GEOM", line 1990
    Any ideas why this isn't working?
    (P.S.: I couldn't find a specific board for Oracle Spatial, hence put this question here--if there's a better place for this question, then, admins, of course, feel free to move the thread to the appropriate spot)

    Hi,
    The SPATIAL forum is here : {forum:id=76}

  • Basic Query on CQ 5

    Hi,
    I have a basic query about CQ5 ,actually i will be getting training on it ,i have the following doubts:-
    1)I am a beginner in JAva and related technologies,does one need to be an expert in java to understand CQ5?
    2)I have mainly worked on Teamsite CMS before,how easy is it for someone from that background to adapt to DAY CQ/
    I can go through all the java concepts which are mandatory in CQ5 understanding,please guide regarding them.
    Looking forward for expert guidance.
    Regards,
    Raul

    Hi Raul,
    Here's my 2 cents:
    1)I am a beginner in JAva and related technologies,does one need to be an expert in java to understand CQ5?
    No - and - depends.  CQ is an enterprise level CMS.  As such, it has many many bits and bobs.  There is a back-end Java element, a front-end JavaScript/ExtJS element, and a bunch of stuff between the two (sling, crx, osgi, etc.).  My best recommendation would be get on a project with a skilled architect in which you are being given components or other parts/pieces to work on. That will give you hands on guidance on building CQ and direct access to seeing an entire project go up from soup-to-nuts.  Also, if you haven't already, try to get to an Adobe CQ Dev training class.  That will really help jump start your knowledge and get you off on the right foot.
    2)I have mainly worked on Teamsite CMS before,how easy is it for someone from that background to adapt to DAY CQ/
    Any previous CMS knowledge is definintely helpful.  Teamsite is VERY different to CQ.  However, the goal is the same.  Content authors need a way of entering content that ultimately gets displayed and served up as a web page.  Teamsite does this with forms whereas CQ does this more inline on the page... If you've ever worked with Teamsite Sitepublisher, that's even better.  Either way, having CMS experience is definitely helpful.
    Todd

  • Woogly - I need U Urgent - please reply if U R there !

    Woogly - I need U Urgent - please reply if U R there !

    Thanks.
    Its already posted:
    http://forum.java.sun.com/thread.jsp?forum=54&thread=480050
    Woogly had gave me last time very useful help getting a container over a container.
    Now I'm dealing with converting the same stuff to Applet, but of course..
    I'll be glad and thankful for help also from others.
    Thanks agian.

  • Please reply its urgent

    it is only wokring when i only assign value to sub1 variableassign
    <html>
    <body>
    <%@ page language="java" import="java.sql.*" %>
    <%
    String[] list=request.getParameterValues("list");
    // String list=request.getParameter("list");
    int i;
    String sub1;
    for(i=0;i<list.length;i++)
    try
    sub1=list;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:dsn1","","");
    Statement stmt=con.createStatement();
    stmt.execute("delete from mes where sub='"+sub1+"'");
    out.println(sub1);
    stmt.close();
    con.close();
    catch(Exception e)
    {out.println(e);}
    %>
    Click here
    </body>
    </html>

    Doublepost: http://forum.java.sun.com/thread.jspa?threadID=5192841
    Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5192927
    Like I said in your former topic: just debug it. Run the debugger or put some simple System.out.println() lines to check if the array has a length, if the array elements are not null, if the final SQL statement is correct, etcetera.
    By the way, with putting pressure by shouting "please reply its urgent" you don't gain that much respect from our side. Some will refuse to reply. Urgency is your issue, not ours.

  • !!!-Need help for terminating a Java thread in real time

    Hi everyone!
    I use J2SDK1.4.1 on a Unix platform.
    I want to terminate (or stop) a running java thread, which is dealing with time consuming tasks, in real-time (for example: the delay before the thread is terminated can't beyond one second), However, I don't know which techniques I can use to make sure the previous (or old) running java threads have been terminated?
    Could you please give me any help if you can?
    Any suggestion or reply will be kindly appreciated!
    Thanks!

    Thanks very much, jverd !
    I do set a flag that the thread should periodically check !
    Well, the scenario is like this:
    1. the thread read line by line (using BufferedReader) string from a probably huge-size file
    2. analyse each string read from the file if required (some strings may be omitted based on the user's operations), the analyzing process is a time-consuming task, and the analysing process may be terminated at any time the user want.
    3. record only the strings that have been analyzed by the previous process into a recording file
    The problem I meet is as follows: (Here, I suppose that it should take at least 30 seconds to finish analyse all the strings in a given huge file )
    1. the user start the analysing process, and run it for only 5 seconds,then stop the analyzing.
    2. the user start the analysing process again from the begining of the file(analyse the strings within the same file as previous step), and then stop the analysing process at 10 second. (it means, this time the analysing process is running for 10 seconds, still haven't finish analyse all the strings in the file).
    Once I open the record file, I saw some of the strings in the recording file have been repetitively record for 2 times, and the repetitive strings are just the strings the analysing time from at 5 second to at 10 second.
    And the repetitive times are depend on how many time the user start and stop the analysing process using the same file. for example, based on the above two steps, the user do the third step as follow:
    3. the user start the analysing process once again, analyse the same file,too. And run it for 15 seconds
    This time open the recording file, this time I saw some of the strings have been repetitively record for 3 times, and the repetitive strings are just the strings the analysing time from at 10 second to at 15 second.
    So, I guess the problem is probably because the previous analysing threads haven't been terminated completely, or say they just are blocked or set as inactive etc., then when the next time start the analysing process, the old threads will be reactive,and rerun ffrom the last time they are blocked.
    I hope you had catched what I mean, if you not, please ust let me know, I'll try to explain it again.
    Thanks once again!

  • Java Threads Problem

    Hi, I am trying to write a simple java threads program where in one thread reads a file and another thread writes the data into a second file....
    Here is my code, although i think i am correct, my program still runs in a sequential fashion help help help!!!
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    class MyThread extends Thread{
    private int a;
    private int c;
    FileInputStream in;
    FileOutputStream out;
    public MyThread(int a){
    this.a = a;
    public void run(){
    if(this.a==5)
         try {
         in = new FileInputStream("Britney.txt");
    } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    try {
         while((c=in.read())!=-1)
              a = (char) c;
              System.out.println(a);
    catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    if(this.a==10)
         try {
              out = new FileOutputStream("romi.txt");
         } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
         for(int i = 0;i<50;i++)
              try {
                   System.out.println(c);
                   out.write(c);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    class MainMyThread{
    public static void main(String args[]){
    MyThread thr1, thr2;
    thr1 = new MyThread(5);
    thr2 = new MyThread(10);
    thr1.start();
    thr2.start();
    }

    Encephalopathic wrote:
    malcolmmc wrote:
    ... Chances of getting any kind of reply except "me too" can be pretty remote. ....there's actually a better chance of getting a reply on a general forum like this one, ....Can't you just post in both the narrow and the general forum, but include links one to the other in each thread? Or is that against the forum rules/etiquette? Most people here are ok with a crosspost IF those links are included.
    I would also ask that the OP designate one of those threads as the real discussion thread and just direct folks there from the other threads, so that we have one coherent discussion. If he does that, there's no problem with trying to reach out to as broad an audience as possible.
    I would figure that if the poster were upfront about what they are doing, folks wouldn't mind, but I could be wrong.I think that's generally the case. As long as the discussion is confined to one thread (and pointed there from the crossposts) or at the very least all the participants can see all the discussions, I think most people don't have a problem with it. It's when we waste our time answering when he's already got the answer elsewhere that's annoying.

  • Error occurred while sending query result: 'java.lang.NullPointerException'

    I am doing end to end scenario from SQL server to File
    JDBC --XI -- File
    I am getting the following Error while monitoring the sender CC in RWB
    "Error occurred while sending query result: 'java.lang.NullPointerException'
    Please Help !!

    Hi,
    To see the Adapter Error log, try:
    http://<XiServerHostName>:<J2EE-Port>/MessagingSystem
    Try viewing the Audit Log for each message (Newspaper Icon)
    Regards,
    Amitabha

  • Problem while querying from java

    I have a query like this ...
    Select name,description,start_date from Events where TO_CHAR(start_date,'MM/DD/YYYY')='09/19/2004';
    I want to execute the same query using java for which i say
    String QQQ="Select name,description,start_date from Events where TO_CHAR(start_date,'MM/DD/YYYY')='?/?/?'"
    PreparedStatement stmt = conn.prepareStatement(QQQ);
    stmt.setString(1,"09");
    stmt.setString(2,"27");
    stmt.setString(3,"2004");
    But I am not getting the results. Is there anything wrong with the Qusetion marks(?) in the query ?
    I get the results if i directly enter the value for the question mark.
    Please help.
    Thanks.

    Date date = get a Date object somehow, perhaps from SimpleDateFormat.parse()
    String query = "Select name,description,start_date from Events where start_date = ?";
    PreparedStatement ps = con.prepareStatement(query);
    ps.setDate(1, date);
    ps.executeQuery();

Maybe you are looking for

  • Creating new apple id with old email address

    Our old G5 has crashed and burned, we just bought a new 27" Imac and are trying to register it but It's been so long that I dont remember the apple id. When I try to start from scratch and create a new id it keeps telling me the email address is alre

  • Different view of the same query between users

    Hi at all, I strongly hope you can help me. The problem that i have is that: I have a different view of a query inserted in a workbook respect the view of the same query that have other users. In particular I watch in my query 4 fixed characteristic

  • XSLT Fragment question

    I am using an XSLT fragment in order to display an RSS feed on a webpage. The problem is that there is a large space at the top of my fragment. I would like to get rid of this space. Anyone know how to do this?

  • ITunes will not open on Mac

    When I open iTunes the following message appears, "iTunes quit unexpectedly", then it asks to reopen and when I do the same error code appears.

  • My sequence markers are not been saved

    I have a new Imac  Processor  3.4 GHz Intel Core i7  Memory  16 GB 1600 MHz DDR3  Graphics  NVIDIA GeForce GTX 680MX 2048 MB I installed Adobe Premier CC and rum the lates updates. After I create multiples annotations markers in each clip, the progra