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
Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

inner class thread

Is it safe to use inner class thread in MainScreen? Something like,

 

public class BaseScreen extends MainScreen

{

class InnerThread extends Thread

{

public void run()

{

 Network connectivity

}

}

}

 

 

A Y.

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: inner class thread

Hi Avi,

 

I don't know what you mean by safe, but I know it's not good practice.

 

The thread can keep on running even when the user closes the screen and then the OS might not be able to close the screen until the thread is done which can cause memory leaks.

 

Also, you will probably have to do some more networking, which means you will have to duplicate your code (at least the connection managing) which is bad coding.

 

E.

Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: inner class thread

Erez, thanks for your reply! I know it is not best of the practice, but the project in which I am workin on is been designed little complex. They are using many parser and network connection, I thought it would be safe if I put it in a thread seperatley for every screen!

 

A Y.

Highlighted
Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: inner class thread

There might be a problem if the server is responding based on the client input.

 

Consider the case of two screen A & B. Each screen has its own thread.

 

Screen A insert records and screen B reads some records.

 

Since there is an option that thread B will run before thread A, there is a chance that you will present wrong data to the user (the request from thread B was done before the insertion from thread A was committed).

 

Personally, I would worried more about changes in the connection flow (changing transport, adding/removing parameters, etc'). Each change requires changes in many places in the code and much more QA work (need to check each screen that was updated).

 

E.