Threads for beginner

Hi,
I'm very much beginner of this game, and I got this problem, do not know how to solve it correctly. I got a list of objects and a list of handler corresponding to the object. They are put on a TreeMap,
map.put(new objectA(), new handlerForA( param1, param2 ));
map.put(new objectB(), new handlerForB(param1, param2 ));Then when the system found the object instance of key
while(true){
handler = (map.get(some_object);
if (handler != null){
   handler.setObject(some_object);
   handler.start();
}// end if
}// end while So handler are subclass of Thread.
My problem is the single instance of "handler". Because when a new "some_object" comes into the system, by passing to the single instance of handler class, using method "setObject()" I overwrite the previous copy of the "some_object".
What I want is a way to take this single instance of the handler, starting a new thread and overwrite the thread code with the same copy of the handler (or execute the handler in a different area of memory).
I'm stuck!

You probably don't need to use threads to handle this problem. Instead of putting the handler in the map, put something in the map which can create a handler, that way instead of singletons, you will have new objects each time. Though I suspect once you do away with the threads, you will not encounter the problem you describe.

Similar Messages

  • What ru the concepts to cover for beginner in sap abap

    Hi fr , This is kumar , what ru the concepts to cover for beginner in sap abap

    Hi Kumar,
    SAP has a certification program for ABAP, according to which following courses are supposed to be covered. If you will try to cover this course, you will be at a level where you can independently program.
    <i><b>1. SAP Technologies
    -> SAP systems
    -> Technical structure of SAP WAS
    2. ABAP Workbench Basics
    3. Advanced ABAP
    4. ABAP Objects
    5. ABAP Dictionary
    6. List creation techniques(including Object oriented ALV)
    7. Dialog Programming
    8. Database Changes
    9. Enhancements and Modifications
    -> Changes to standard SAP system
    -> Personalization
    -> Enhancements to ABAP Dictionary elements
    -> Enhancements via customer exits
    -> Business transaction events
    -> BADI
    -> Modifications</b></i>
    Following are some links which will help you to cover above points.
    http://www.sap-img.com/F
    http://www.sappoint.com/abap.html
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/ranges.htm
    http://www.sapdevelopment.co.uk/programs/programsalv.htm
    http://www.geocities.com/victorav15/sapr3/abapfun.html
    http://abap4.tripod.com/SAP_Functions.html
    http://sapr3.tripod.com/abap011.htm
    http://abap4.tripod.com/Other_Useful_Tips.html
    http://www.sap-img.com/abap/how-to-change-the-development-class.htm
    Hope this helps you.
    PS If the answer solves your query, plz close the thread by rewarding points to each reply.
    Regards

  • I get two message threads for one contact. One for sms and one for iMessage since I updated to iOS 7. How can I get them both into one thread?

    Ever since I upgraded to iOS7 just two of my contacts I get two message threads for them. One containing their iMessages to me and the other with just regular sms messages. In Contacs, their email and phone number are saved under one name. How can I get the iMessages and sms to come through under one thread in my messaging app again?

    I am having this trouble also, my partner creates a new message to send to me, or sends a picture and it always comes through as an MMS and not using iMessage ...
    will try deleting everything and starting again!

  • Error encountered while signing. Windows cryptographic service provider reported an error. Object not found. Error code:2148073489. Windows 7, Adobe Reader XI, Symantec PKI, Smart Card and CAC. I have seen other threads for this error but none have a reso

    Error encountered while signing. Windows cryptographic service provider reported an error. Object not found. Error code:2148073489. Windows 7, Adobe Reader XI, Symantec PKI, Smart Card and CAC. I have seen other threads for this error but none have a resolution. Any help would be appreciated.
    Sorry for the long title, first time poster here.

    This thread is pretty old, are you still having this issue?

  • Suggestions thread for ABAP FAQ sticky

    See these threads for "online collections" in the ABAP Development forums =>
    FAQ's, intros and memorable discussions in the ABAP General Forum
    FAQ's, intros and memorable discussions in the ABAP Data Dictionary Forum
    FAQ's, intros and memorable discussions in the ABAP UI Programming Forum
    FAQ's, intros and memorable discussions in the ABAP Form Printing Forum
    FAQ's, intros and memorable discussions in the Enhancements & Modifications
    FAQ's, intros and memorable discussions in the Performance and Tuning Forum
    FAQ's, intros and memorable discussions in the Data Transfers Forum
    FAQ's, intros and memorable discussions in the ABAP Objects Forum
    Edited by: Julius Bussche on Apr 21, 2009 5:22 PM

    ABAP General
    Subtotals in alv list.   => Subtotals in ALV    <= Added and moved to UI programming
    Can we modify a sub-total in ALV => Subtotals text in ALV /Modification of Subtotals in ALV   <= Moved down to new thread.
    cl_salv_table - Save Layout =>  ALV OM Save layout option <= Moved down to new thread.
    Report with page break.   => ALV Report with page break. <= Moved down to new thread.
    ALV Sorting Not Working after Adding Checkbox to ALV => ALV Sorting and Group Functionality working with Checkbox <= Moved down to new thread.
    Calculating Total with Checkbox in ALV Grid => Calculating Total with Checkbox in ALV Grid  <= Moved down to new thread.
    DUMP WHILE SUMMATION IN ALV  => General Fieldcatalog error.  <= Moved down to new thread.
    Problems with REUSE_ALV_FIELDCATALOG_MERGE =>Problems with REUSE_ALV_FIELDCATALOG_MERGE   <= Moved down to new thread.
    Must i_structure_name for LVC_FIELDCATALOG_MERGE be pre-defined in dict?   => Converting SLIS fieldcatalog to LVC fieldcatalog  <= Moved down to new thread.
    Capture Checkbox Value in ALV Grid   => Capturing the editable fields values in ALV   <= Moved down to new thread.
    how to refresh table display using slis and 'reuse_alv_grid_display method. => Refreshing the ALV Display  <= Moved down to new thread.
    fetch data in edittable field in alv using REUSE_ALV_GRID_DISPLAY_LVC FM => Reading the editable values for ALV LVC function  <= Moved down to new thread.
    Radibutton in ALV Report output => Radio buttons in ALV report  <= Moved down to new thread.
    Edit rows in ALV => Usage of Styles in ALV for disable/enable input option  <= Moved down to new thread.
    how to copy/delete file => executing Unix commands <= Hmmm... c-calling the 'system' does not work in my systems during normal operations. See system param 'rdisp/call_system' which can be disabled, then the code dumps. Is there a different thread with DATASET commands? SXPG?
    express CR_LF => ABAP char Utilities CR_LF use , replace '##' in a application server <= Ahhh yes, I remember this series. This is one of the nicer threads from it... Added.
    String Operations which contain the special character '#' in BDC Session => ABAP char Utilities Horizontal_tab use , replace '#' in application server file <= Sufficiently covered by the next thread.
    Problem with statement "find all occurences of ..." => ABAP char utilites Newline, replace '#' in application server in end of line <= Added.
    How to Send Email to Outlook? =>sending mails to outlook <= Added.
    FM for uploading Image to SAP => upload image to mime repository <= Added.
    Passing an Internal Table to a Report executed through 'Submit' => use of Import and export refer Rich Heilman's code  <= Added.
    Create a parameter to enter a password => Selection parameter password behaviour  <= Added.
    ABAP Dictionary
    =>
    Form Printing
    Exporting Graphics from SAP =>Download Logo from SE78 <= Okay, added... but the thread is rather old and ws_download is obsolete now, isn't it?
    BDC for SE78 Transaction  => Upload Logo programatically <= Hmmm... external performs and guests. I would like more opinions on this one before adding.
    UI Programming
    [Top of page in OO ALV|TOP_OF_PAGE in ALV  Using CL_GUI_ALV_GRID ]=> Top of page in OO ALV <= I understand that this blog was very helpfull, but it is full of email addresses. Hmmm.. tough call Is there another example (thread) without any "here is my mail address" comments. We want to avoid those.
    [Top of page Alignments in Normal ALV|Alignment of  Data in TOP-OF-PAGE in ALV GRID] =>  Top of page in normal ALV <= this is more wiki material in a blog, but again often asked... Hmm.. lets go through the others first and come back to this one.
    To display URL as a hyperlink (along with simple text) in dialog program   => URL display using HTML Viewer  <= Added.
    select-option on dynpro => Select-options usage in Module pool programming  <= Added.
    New! =>
    Enhancements and Modifications
    =>
    ABAP Performance and Tuning
    =>
    Data Transfers
    =>
    ABAP Objects
    =>
    Edited by: Julius Bussche on Oct 3, 2008 10:31 PM
    Edited by: Julius Bussche on Oct 3, 2008 10:34 PM
    Edited by: Julius Bussche on Oct 3, 2008 10:38 PM
    Edited by: Julius Bussche on Oct 3, 2008 10:43 PM
    Edited by: Julius Bussche on Oct 3, 2008 10:55 PM
    Edited by: Julius Bussche on Oct 4, 2008 12:06 AM
    Edited by: Julius Bussche on Oct 4, 2008 12:40 AM
    Edited by: Julius Bussche on Oct 4, 2008 12:57 AM
    Edited by: Julius Bussche on Oct 4, 2008 1:23 AM
    Edited by: Julius Bussche on Oct 4, 2008 3:27 PM
    Edited by: Julius Bussche on Oct 4, 2008 3:39 PM
    Edited by: Julius Bussche on Oct 4, 2008 5:40 PM
    Edited by: Julius Bussche on Oct 4, 2008 5:59 PM
    Edited by: Julius Bussche on Oct 4, 2008 7:17 PM

  • 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 is it possible to make sure that LV uses the same thread for several threadsafe DLL calls?

    Hello,
    i have a thread safe DLL and most functions are called from serveral threads from the LV apllication without problems.
    In case of an error i have to call an error handler function in this DLL (like WinAPI: GetLastError()) from the same thread which has called the function that failed before.
    I can't use the user interface execution because some functions need a long execution time and i don't want to balk the user interface.
    All other executions than the user interface execution have more than one thread and in most cases the DLL function calls were executed from different threads - so the error handling doesn't work...
    Any idea?
    Thanks for your help!

    Hmmm....
    How about wrapping all of your dll calls in a single VI (or an Action Engine ) and make sure the VI's thread is NOT set for "Same as caller".
    "Threadconfig.vi" (sp?) will also let you dictate the number of threads associated with an execution system. Set your target thread for "1".
    Not sure on the above.
    Please correct me if this is wrong!
    Ben
    Message Edited by Ben on 07-19-2007 08:26 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Number of threads for imap process

    What is the resonable nimber of threads for imap procerss?
    I have 2 impad procrss and number of threads more then 200!!!
    I think this is to much for 700-900 concurrent impa connection&
    What is the reasons for this big number

    Actually, your configuration sounds pretty close to correct for your load.
    We allocate up to 250 threads, as many clients connect more than one time per session, and open more than one folder at a time.
    I would not mess with the number of threads.
    If most of your users have small numbers of messages and folders, you may be able to get away with a single imap process, but if you have several processors, two is fine, too.
    Is there a problem or error situation you're trying to work around? What exact version of Messaging do you use? (imsimta version gets that)

  • Running a thread for a specified time

    my main program has 10 threads. i want to run each thread for 30 secs . but if one thread is on progress it may be allowed some time to complete its task otherwise evrbody should return after 30 secs.how can i do it ?
    thankx

    code is hanging...
    also how do i do >>if one thread is on progress it may be allowed some time to complete its task otherwise evrbody should return after 30 secs
    class Shared
    boolean stop=false;
    // do nothing but helps only for synchronisation
    class ThreadProducer1 extends Thread
    {    Shared obj;
         public void run()
         {   long endTime = System.currentTimeMillis() + 30 * 1000;
             long currentTime;
              for (int k=0;k<1000;k++)
              {System.out.println("thread1");     // doing its work
             currentTime=System.currentTimeMillis();
              if (currentTime>endTime) break;
    class ThreadProducer2 extends Thread
    {   Shared obj;
         public void run()
         {   long endTime = System.currentTimeMillis() + 30 * 1000;
             long currentTime;
              for (int k=0;k<1000;k++){
              System.out.println("thread2");     // doing its work
              currentTime=System.currentTimeMillis();
              if (currentTime>endTime) break;}     // doing its work
    class ThreadProducer3 extends Thread
    {   Shared obj;
         public void run()
         {   long endTime = System.currentTimeMillis() + 30 * 1000;
             long currentTime;
              for (int k=0;k<1000;k++)
              System.out.println("thread 3");     // doing its work
              currentTime=System.currentTimeMillis();
              if (currentTime>endTime) break;
              }     // doing its work
    class Test
    public static void main(String argv[])
        try{
         ThreadProducer1 t1 = new ThreadProducer1();
         ThreadProducer2 t2 = new ThreadProducer2();
         ThreadProducer3 t3 = new ThreadProducer3();
         t1.start();
        t2.start();
         t3.start();
        Thread.sleep(30000); // main thread wakes up after 30 secs.
         }catch (InterruptedException ex)
             System.out.println("exception");

  • Is there a separate discussion thread for educators using ibook?

    Many of us in higher education are trying to use ibooks as text or as lab manuals.  Are there discussion threads for the particular ibook issues teachers/instructors/professors might come across?  Thank you.

    No, unless you are into the production of ebooks, then there are forums at
    https://discussions.apple.com/community/books?view=discussions

  • Thread for USA Payroll

         Please let me know the thread for USA Payroll??
    So that i can post questions

    i moved your thread to US forum u can post your queries here

  • Best Manual For Illustrator CS2 For Beginner

    Best Manual For Illustrator CS2 For Beginner
    Hello,
    Can someone please give me suggestions on a good and simple
    beginners manual for Illustrator CS2?
    Thanks,
    Diane

    Error: "Activation Server Unavailable" | CS2, Acrobat 7, Audition 3

  • Help with Threads for a webserver

    That is the main class of my webserver. The problem is that after executing one petition the server closes with exit status 1. Normally that should never happens as it does not happen at the single-threaded server. Any suggestions ??
    Also do i have to impement monitors, meaning syncronized functions to monitor buffers and some static variables ?
    This is my first program impementing threads so really i do not experience over it
    package jhttp_server;
    import java.io.*;
    import java.net.*;
    import java.lang.*;
    * <p>Title: JHTTP_server</p>
    * <p>Description: A simple HTTP server implemented with Java</p>
    * <p>Copyright: Copyright (c) 2004 - Lisenced under GPL</p>
    * <p>Company: Universidad Rey Juan Carlos</p>
    * @author Panayiotis Papadopoulos -> [email protected]
    * @version 0.1
    public class jserver {
    static ServerSocket serverSocket = null;
    static PrintWriter out;
    static BufferedReader in;
    static Socket client = null;
    static short i=0;
    static int port;
    static boolean newSock=true;
    public static void main(String[] args) throws IOException {
    port = Integer.valueOf(args[0]).intValue();
    try {
         serverSocket = new ServerSocket(port);
    catch (IOException e) {
         System.out.println("Must Enter a port number");
    System.out.println("|------------------------------------------------------------------------|");
    System.out.println("|JHTTP Server initialized and accepting connections on port:" +
    serverSocket.getLocalPort()+"\t |");
    System.out.println("|------------------------------------------------------------------------|");
    while(true){
    while (i < 5) {
    i++;
    try {
    //Creating if needed a new socket where the clients listens
    if (newSock) {
    client = serverSocket.accept();
    in = new BufferedReader(new InputStreamReader(client.getInputStream()));
    out = new PrintWriter(client.getOutputStream());
    System.out.println("LOG: Client is listening on port: "+client.getPort());
    //Here the server creates a new thread for the petition
    petition newPet = new petition();
    newPet.T.start();
    } // try- create input and output buffers
    catch (UnknownHostException e) {
    System.err.println("JHTTP Server could establish a connection. Exiting...");
    catch (IOException e) {
    System.err.println("Could not get I/O for the connection to client.");
    } //try - create client sockets, wait and attend connection
    } //while 5 petitions
    System.out.println("Session Closed. 5 continious petitions served.");
    out.close();
    in.close();
    client.close();
    newSock = true;
    System.gc();
    i=0;
    } // while - forever
    }// -------------------main-------------------
    }// jserver - main class of JHTTP server project
    class petition implements Runnable {
    Thread T;
    petition () {
    T = new Thread(this);
    T.start();
    public void run() {
    try {
    //Analyse petition
    Petition_Analysis.Analyse_Petition(jserver.in);
    //Then Attend it
    if (Petition_Analysis.pt.Version.equals("v10"))
    Http_10.Attend_Petition(Petition_Analysis.pt, jserver.out, extra.detectConnectionAlive());
    else if (Petition_Analysis.pt.Version.equals("v11"))
    Http_11.Attend_Petition(Petition_Analysis.pt, jserver.out, extra.detectClose());
    else {
    jserver.out.print("HTTP/1.0 400 Bad Request\r\n\r\n");
    jserver.out.close();
    jserver.in.close();
    jserver.client.close();
    jserver.newSock = true;
    //The following function immediately prints the contents of the PrinterBuffer
    jserver.out.flush();
    System.gc();
    catch (MalformedURLException murle) {
    jserver.out.print("HTTP/1.0 400 Bad Request\r\n\r\n");
    try { jserver.client.close(); }
    catch(IOException ioe) { System.out.println(ioe); }
    jserver.newSock = true;
    catch (NullPointerException npe) {}
    //try - analyse petition & attend it
    catch (IOException ioe){
    System.out.println(ioe);
    } // -- run()
    } // --class: thread

    Use code tags when posting code.
    Given that the code you presented does not call System.exit() I am not sure how it could be exiting with a value of 1.
    When you accept a connection from a client the code should do nothing but pass the client socket off to a thread and then start that thread. It should not extract the streams - do that in the thread.
    The in/out streams of the client socket should be wholly contained within the thread/Runnable. They do not belong to the class that holds the SockerServer.
    Your catch blocks need to be reworked. The first one completely ignores the exception and prints out that a port number is needed. You should be printing the exception message at a minimum and right now you should be be doing a printStackTrace() as well. Additionally you are ignoring a null pointer exception and that is wrong.

  • Oracle 9i book for beginner?

    Hi,
    I have about 5 years experience in developing database applications with Microsoft programming tools and SQL Server.
    I want to start working with Oracle 9i.
    Is there any recommended book on Oracle 9i for beginner?
    Thanks in advanced,
    Asaf
    [email protected]

    Hi Asaf,
    There is a huge collection of books on OTN on Oracle technologies at [url http://tahiti.oracle.com/]this link. Have a look at it. You can even check the online SQL documentation at [url http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/toc.htm]this link.
    Regards,
    Anupama
    [url http://otn.oracle.com/sample_code/]OTN Sample Code

  • The best mod information thread for NB550D/02F

    Hey Mini Toshy fans,
    There is no FULL solid post on the net of how far you can actully push this hardware from start to finish.
    In this post and further postings from YOU...I wish to make a one-stop thread for geeks on this latest unit.
    The 32bit OS win 7 [home, professional, ultimate] is the best supported for the AMD grafix chipset and various other drivers of ure choice this is the best information I have gathered......plz correct me if Im wrong?
    Also if new 64bit changes come thru please post in this thread :D
    So what us geeks need to know is the information for the SATA controller on the board for the Toshiba NB550D/02F PLL5FA-02F02C, other newer models
    I have some sketchy information it could be SATA3 which will support an upgrade of a SSD 6GBs controller and some saying it is SATA2 is on the board supporting 3GBs but the S3 connection will still work saturating the speed connection of the S2.
    So lets get ALL the best mod information for this unit sorted here and now !!
    Post away.....and thx 8>)

    So further study I did says 3.5gb of RAM will be usable on a re-install on a 32bit OS of your choice or you can patch the kernel with a patch if you wish to get the full 4gb personally I will not touch the kernel and will be happy with 3.5 than risk security exploits. However that one is up to you......you can Google "extend x86 RAM patch". So we still need the info from a techy who has a SSD installed and can give us SATA and SDD information they have found. Peace and thx again.

Maybe you are looking for