Where is better to create Thread?

I know there are two way to create thread, one is in subclass of MIDlet for itself
public class BaseDevice extends MIDlet implements Runnable {
private Thread thread;
protected void startApp() {
     if (thread == null) {
          thread = new Thread(this);
          thread.start();
another is in subclass of Canvas or GameCanvas, I want to know which one is better.
public class BaseDevice extends MIDlet {
     public static BaseCanvas canvas;
     public NumberPlace() {
          canvas = new BaseCanvas(this);
          Display.getDisplay(this).setCurrent(canvas);
          (new Thread(canvas)).start();          
}

hi, why do we need thread? either you are doing some n/w related task or animation.
so better make thread in that class where you are doing such task. so in this case make in subclass.

Similar Messages

  • Creating threads based on information read from a configuration file

    Hi. I'm writing a program where I need to use threading. I've done some threading in my past, but I'm no expert. What I need to do is create a number of threads dependant on how many are requested
    So I have a conf file where:
    SomeValue = String1, String2, String3, String4
    I read those values and right now I stick them in an Array. So in this case I have four slots in the array filled.
    How can I declare a simple unique thread for each of them?
    I've searched the forums and found a few references to this, but I'm not able to make it work. I'm still googling for answers now. If anyone understands what I'm attempting and can help I'd really appreciate it.
    Thanks,
    James

    Thanks for the reply. I'm looking at the tutorials, but I'm having some trouble understanding. It's been quite a while since I played with threads and I can't find the code I did them in to refresh my memory. I have a small application in one class with several funtions like:
    public class MyProgram {
         public void funtion1() {
              does something
         public void function2() {
              does something
         public MyProgram(String args[])     {
              calls functions;
         public static void main(String[] arguments)
            MyProgram instance = new MyProgram(arguments);
        } Where do I implement runnable in a case like this?
    Do I get rid of public static void main somehow?
    Does MyRunnable need to be a seperate class?
    Back to the tutorials....
    Thanks,
    James

  • Listeners, load a class on startup and creating threads in infinite loop

    This is an identical post to the one I made in the jsp forum. I do this as I know, being a regular here, that there are equally good people(in j2ee web application development) in both these forum, but many of them stick to their particular forums of choice - jsp / servlets.
    I was wondering if there is any means by which I could launch my own class when tomcat starts (in the same jvm).
    1. I need one or more Thread/TimerTask because the requirement is such that the application would have continous data drops (in the form of logs) which has to be picked up, parsed and pushed into a db. Another part of the application reads the data from the db on requests (http) and displays it over the web. The thread has to poll for arrival of new logs and then hand it over to a framework for parsing and inserting the parsed data to a db.
    2. I know that I can possibly use a servlet with a load-on-startup value greater than 1 and code my requirement into the init method. However, using a servlet for a functionality different from servicing http requests has me worried. (valid ?), not to mention the fact that Iam very uneasy about creating threads from within Servlets.
    3. I googled hard and found that I could probably use a tomcat specific context lifecycle listener.
    4. I could also possibly use the servlet api - the ServletContextListener.
    5. I have rejected #2 and settled on either #3 or #4 - the ServletContextListener or Tomcat specific Lifecycle Listener, though the later, as I said binds me to Tomcat (which is ok for me). Are there any other specific (dis)advantages of using either especially when I have to create threads from within them (on context startup)? Other than memory leaks, killing the thread objects & associated resources on context shutdown, is there anything else that I need to watch out for while using threads.
    6. I wonder is there is there a plain startup hook available in tomcat (rather than listeners) - from where I can launch a class that starts a thread in the same jvm as tomcat's ?
    Thanks In Advance,
    Ram.

    Anybody ? Sorry for bumping up.
    Thanks,
    Ram.

  • Creating threads in init for servlet (advanced)

    Hello
    we have a servlet ..in servlets init method we are creating new threads by calling the Timer class like this
    BGMSchedul = new Timer(true);
    BGM = new BackManager();
    BGMSchedul.scheduleAtFixedRate(BGM, 10000, 30000); //every 30 secondsProblem is that during our stress testing on IBM WSAD we've noticed errors like J2CA0075W: An active transaction should be present
    Upon researching this issue further i found this link http://www-1.ibm.com/support/docview.wss?rs=180&uid=swg21231761
    which i think suggests that the servlet shouldnt be creating threads which make J2C connections. Our thread is making the DB connection.
    does nay one have experince with this sort of problem? is it a bad programming construct to create threds in a servlet? if so..where should we be creating our threads? we want this thread to run every 30 seconds and this is a web appliction.
    I'd appreciate any help

    I've created a POJO class that implements servletcontextlistener and took out the time thread from servlet and placed it in pojo's contextInitialized method. however, i still get the same warning.

  • Creating threads in Weblogic

    For a variety of reasons I need to write my own messaging bridge between Weblogic and MQ. The reasons have been validated by BEA, so I'm not completely off my rocker :)
    I can either write this as a standalone java application that acts as a client to weblogic's JMS server, or as a deployed webapp (using the ServletContextListener method to start/stop it). Either way the app will <shudder>create one thread per queue</shudder> and listen on that queue until a message arrives.
    The pros of a deployed application (cost-free clustering, management, can use a webapp to manage the threads/queues, etc) leads me in that direction, but creating threads in a J2EE server dubious at best.
    Ideally this webapp runs in its own execute queue, and the holy grail is to have the threads run in that execute queue. However, there doesn't seem to be any supported way to create threads from an execute queue.
    Has anyone done anything like this? Any suggestions on how to spawn and manage the threads properly? Should it be deployed or stand-alone?
    cheers
    mike

    Hello,
    The webapp route sounds better to me than a standalone java app, you will get things up and running a lot more quickly and get all the goodies associated with webapps.
    You don't explicity create threads from the queue for example in the way you get connections from a connection pool. Once you have created and configuered your execute queue you just add a few init parameters to your web.xml deployment descriptor:
    <servlet>
    <servlet-name>MainServlet</servlet-name>
    <jsp-file>/myapplication/critical.jsp</jsp-file>
    <init-param>
    <param-name>wl-dispatch-policy</param-name>
    <param-value>CriticalAppQueue</param-value>
    </init-param>
    </servlet>
    see:
    http://e-docs.bea.com/wls/docs81/perform/AppTuning.html#1105201
    for complete instructions.
    cheers
    Hussein Badakhchani
    www.orbism.com

  • Problem creating threads

    Hi,
    I'm trying to make a LabView application that creates threads, which set and
    unset digital lines. For some reason I can't include attachments to my posts,
    but I'll try to explain what I have done so far.
    I have a one VI that runs forever in a while loop and sets a digital line to 1 or 0
    every 500 ms. This VI is defined to be reentrant. From this VI I would like to have
    numerous of instances with different digital lines. This VI is supposed to be the
    base from the threads. The digital port is the only thing that is different in each
    thread.
    I use another VI to create these threads with Invoke Method. First this VI uses
    Open VI Reference. Then I use Invoke Method to get the type descriptor of the
    control I want to change in the VI. Next I call Invoke Method to set the digital port
    to be used with parameters gotten from the previous Invoke Method. And finally
    I call Invoke Method: Run VI.
    I get an error that states "Memory or data structure corrupt". The source is in the
    set value.
    Hopefully this makes at least some sense and someone can give me some tips
    on how to do this.
    Thanks.
    P.S. I'm trying add files to my posts from the "Browse..." button that is located at
    the bottom of this message writing page, but for some reason the attachments
    does not show. Am I doing something wrong?

    Thank you LV_Pro and altenbach for your replies.
    I will try to explain this matter more clearly. First of all I'm using the evaluation
    version of LabView 8.2 on Windows 2000. I also have LV 6.2 which I have tried
    this, but we're propably  going to use a 8.x version, so 8.2 will be my main
    environment now.
    I need to make a DLL that will be called from another  application. In the library
    the functions/VIs should run in threads for parallel execution and the application
    using the DLL can't wait for the execution to end. I'm trying to make the functions
    inside the library as general purpose as possible, because those same functions
    are needed for different things.
    If there's some other way to create threads in LabView, please let me know, since
    this is the only way I know, and it's not even working.
    Hope this explains it better. If not let me know and I will draw a diagram or something.
    Thanks.
    Attachments:
    BlinkerThreadRunner.vi ‏15 KB
    DOutBlinkerThread.vi ‏11 KB

  • Where we have to create depreciation key in asset accounting for as02 ?

    Hi all
    where we have to create depreciation key in asset accounting for as02 ?
    Regards
    Saimedha

    Hi,
    Saimedha....
    AS02 is for Asset change..........here you can change only dpercaition keys.......
    You can define in AS93..........under Takeover values.
    Also u can check the value at AS02 under Deperciation area at initial tab ..you can see there at Menu Bar..
    Regards
    Ricky

  • ORA-27054: NFS file system where the file is created or resides is not mounted with correct options

    Hi,
    i am getting following error, while taking RMAN backup.
    ORA-01580: error creating control backup file /backup/snapcf_TST.f
    ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
    DB Version:10.2.0.4.0
    while taking datafiles i am not getting any errors , i am using same mount points for both (data&control files)

    [oracle@localhost dbs]$ oerr ora 27054
    27054, 00000, "NFS file system where the file is created or resides is not mounted with correct options"
    // *Cause:  The file was on an NFS partition and either reading the mount tab
    //          file failed or the partition wass not mounted with the correct
    //          mount option.
    // *Action: Make sure mount tab file has read access for Oracle user and
    //          the NFS partition where the file resides is mounted correctly.
    //          For the list of mount options to use refer to your platform
    //          specific documentation.

  • How do I put a Shortcut Icon on my Desktop linking to a certain Webpage, like I could do with I.E./Google? Where do I find "Create Shortcut' ???

    Question
    How do I put a Shortcut Icon on my Desktop linking to a certain Webpage, like I could do with I.E./Google? Where do I find "Create Shortcut' ???

    Hey, Dynamite !
    Thanks so much for that ... what a 'dynamite' solution. It's so easy. I don't know how you people know all of these things ! But one last thing if you can help me - I've just switched over to Mozilla/Firefox from I.E., and now I cannot open my Hotmail from Mozilla/Firefox. I log in, it goes to my 'Inbox' page, but when I click on an Email letter to open it, nothing happens. I can't even go into 'Drafts' or 'Delete' or anything.
    MitziB.

  • ORA-27054: NFS file system where the file is created or resides is not moun

    Linux Red Hat 4
    10.2.0.4
    Had this issue since someone unplugged the san on Monday, and the servers were rebooted. Trying to do a duplpicate to Reporting Server from Production. The error returned, once the backupsets are being copied, is
    ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
    I have edited fstab in the way that the Doc 781349.1 suggests. I have unmounted the mount point and remounted. Themount is set up this way:
    /backup/PROD on /backup/PROD type nfs (rw,bg,hard,rsize=32768,wsize=32768,nfsvers=3,nointr,timeo=600,proto=tcp,addr=172.16.2.92)
    I have checked fstab and it has write permissions for the oracle user with which I run the duplicate command.
    I am able to browse, and create files on the /backup/PROD area.
    Edited by: user11981168 on May 3, 2010 1:02 PM

    It is my understanding that the NFS mouting options necessary to support Oracle vary based on the hardware/OS in use.
    I have the following recored for a NetApp appliance
    hard,bg,rw,vers=3,proto=tcp,intr,rsize=32768,wsize=32768,forcedirectio
    and this for a Linux Client
    rw,bg,hard,nointr,tcp,vers=3,timeo=300,rsize=32768,wsize=32768,actimeo=0
    I suggest your review your platform specific documentationa and any record you have from the origonal set up.
    You might just want to open a SR where you provide the specific hardware info and see if support can help after making another search for documents of interest.
    HTH -- Mark D Powell --

  • Where and how to create business rules?

    Hi All,
    1) Where and how to create business rules?
    2) How to configure Rule Engines (Ex: JRULE Engine or any other Rule Engines)?
    3) Whar products are available for Rule Engines?
    Thanks in advance

    Hi,
    You have some options on business rules.
    If you just want to create business rules that are easy for business owners to edit without a lot of training, Oracle BPM has a simple business rules creation and end user edit capability. The benefits to using the rules that come with Oracle BPM are:
    <li> they are simple and easy to edit
    <li> end users can get up to speed quickly to edit them
    <li> when changed, the business process is immediately impacted
    <li> they can use the Oracle BPM business parameters that also come with the product
    Drawbacks are:
    <li> you can only use Project variables as the variable content inside of them
    <li> if a company already has a business rules engine, they are different that the company's standard
    Business rules engines have been used with Oracle BPM. If you are a consultant, first ask if there is a standard business rules engine that the company already has purchased that they use (e.g. iLog from IBM, Corticon...). If this is the case, you typically integrate to the rules using a web service interface that the business rules engine exposes.
    If they do not already have a business rules engine, consider Jrules. The benefits are:
    <li> it is a part of the Oracle BPM Suite that they might have purchased
    <li> version 11g of the Jrules is coming out soon with a friendly front end
    Hope this helps,
    Dan

  • I made a project on my PC computer, saving it as a tif. I then took it to the Art Institute, editing it on their Apple  I wish to tweak it at home but now Ps claims that it is not compatible with this cc version of Ps, where it was originally created! HEL

    I made a project on my PC computer, saving it as a tif. I then took it to the Art Institute, editing it on their Apple  I wish to tweak it at home but now Ps claims that it is not compatible with this cc version of Ps, where it was originally created! HELP!!!

    The files are the same, regardless of OS version.
    Most likely your file was corrupted when you transferred it.

  • Hi All, which is better while creating an object

    Hi All, which is better while creating an object,
    for ex:
    public class Joe {
    public void disp() {
    System.out.println("Joe.disp");
    (1) Joe j = new Joe();
    j.disp();
    (2) new Joe().disp();
    of course, both are equal, which is better in performance perspective

    I suggest you just write code and when the assignment is done, AND you have a performance issue, only then try to improve things. The question you're asking now is likely of no relevance to the performance of you application.
    You can run your application through a profiler to see what specific part of it is consuming (too) much memory.

  • Error Code -17400; Unable to create thread

    Running TestStand 4.0.  Test sequence calls many sequences that run as new executions and runs fine for up to about 8 units testing simultaneously.  After that, I get a run-time error code -17400; Unable to create thread.  There are no other details available.  The steps that generate the error are able to create the new executions initially, but eventually fail once about 22 executions are running.  I am monitoring memory resources and there does not appear to be any issues.  Any troubleshooting suggestions?  Thanks.

    My test sequence has several test groups, each of which contain loops that create new threads (tests) for 48 UUTs.  Thus the number of running threads does get very high.  I was running into problems with Windows XP GDI Object resources once the number of threads reached about 200.  I then modified my program into smaller test groups to keep the number of threads at any time to less than 150.  GDI resources are no longer an issue, but the error -17400 unable to create thread happens after the first test group has completed and the second test group is just trying to run.  Note that the second test group runs fine if I skip the first test group, so the sequence itself should be okay.  I thought it might be a memory issue (even though there are no apparent memory issues seen in Windows Task Manager), so I set the "Unload after step executes" property for each of the new executions created.  That did not resolve the issue. 
    I am trying to create a simple sequence to duplicate the error without using any of the actual test sequences that require test hardware, but have not been successful thus far.
    Thanks for your replies and suggestions!

  • Create Thread on Photoshop Plug-in

    Dear All,
    Right now, I am developing a demo Photoshop plug-in software to understand the way to implement Photoshop plug-in. However, I meet a issues that I can not create a Thread on Photoshop plug-in by CreateThread() API. I implement as below:
    Main function:
    CreateThread( NULL, 0, Test1Thread, NULL, 0, NULL);
    Thread function:
    DWORD WINAPI Test1Thread(LPVOID pParam)
    /*Do something*/
    return 0;
    When I compile and load plug-in on Photoshop, it show an error message like this:
    The instruction at "0x09fd100a" referenced memory at "0x09fd100a". The memory could not be "read"
    Click on OK to terminate the program
    Click on CANCEL to debug the program
    Can you give me some suggestions that I can create a Thread by CreateThread() API on Photoshop plug-in or not? And how can I create Thread?
    I am looking forward your answer.
    Thanks for your help,
    Hieu Nguyen.
    PS: I am developing on Window OS and Visual C++ development tool.

    Thanks Aandi Inston and Marcus Phillips for your answer.
    In thread I just use Named Pipe inter-process communication mechanism to send signal to the other application. So I do not use any Photoshop API.
    However, it is strange that I can not put my Thread in begin of PluginMain function:
    DLLExport SPAPI SPErr PluginMain
    ( char* caller, char* selector, void* message)
    SPErr error = kSPNoError;
    SPMessageData *basicMessage = NULL;
    SPPluginRef plugInRef = NULL;
    SPErr err = 0;
    basicMessage = (SPMessageData *) message;
    sSPBasic = basicMessage->basic;
    gPlugInRef = basicMessage->self;
    MyThread();/*CAN NOT RUN THE THREAD!!!!*/
    I must change my Thread function to position after checking caller parameter
    Please show me the reason why?
    Thanks,

Maybe you are looking for