05-24-2012 03:19 PM
Is it safe to use inner class thread in MainScreen? Something like,
public class BaseScreen extends MainScreen
class InnerThread extends Thread
public void run()
05-24-2012 04:08 PM
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.
05-24-2012 05:04 PM
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!
05-24-2012 06:57 PM
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).