Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 59
Registered: ‎06-15-2012
My Device: 9800
My Carrier: XZY

Event Thread

Hey Guys,

                    I have one doubt . i have native application in which i have created many thread 

 

when application starts first time then event Thread is running  and in my program statments i have created another thread which extends the Thread class.

example 

public class MyApp extends UiApplication
{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    

    /**
     * Creates a new MyApp object
     */
    public MyApp()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new MyScreen());
    }    
}
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
	public MyScreen()
    {   
	InstallAppThread install = new InstallAppThread();
        Install.start();

	
    
}
class InstallAppThread extends Thread{


public void run()
{
  //doing operation networking and file creation operation


}


}

 

So in  my case after complition of the InstallThread Process i am checking the Main Thread that is eventThread i am getting the false. but im gettign the correct result .and next time if i fire the request that time event thread is displaying the true result. i am not understanding why it is happaning ???

 

one more doubt . it is better to create seprate thread for file creation(create the file ) and network operation(which store the network result in the created file)  ????

 

 

Peter If u are still not getting this problem let me know i will explain problem in diffrent way .hope u will understand this

 

and yes other can also replay or suggest for best apporch . 

 

Thanks

 

 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Event Thread

There are some potential issues regarding when you start things.  While main(..) is running your Application is not actually in control, as you have not actually

enterEventDispatcher();

 

But once main completes, the same Thread becomes the Event Thread.

 

This is all a little confusing so what I recommend that you do is not actually start any processing until the Application has started.  This is also a little confusing, so you need to think about it. 

 

Anyway, in this case I would actually do the following:

 

Move the Thread start into the constructor for MyApp, and surround it with

this.invokelater(new Runnable() {

public void run() {

InstallAppThread install = new InstallAppThread();
Install.start();

}

});

 

Then the install thread will not run until the application is correctly started, and you should get consistent results.

Highlighted
Developer
Posts: 59
Registered: ‎06-15-2012
My Device: 9800
My Carrier: XZY

Re: Event Thread

Thanks Peter for response