| Reply | « Previous Thread | Next Thread » |
|
Hi All,
I have developed an application based on threads. An application contains two threads which starts separately (separate class for each thread). On first thread I am showing continuous animation & on second thread I am doing socket connection. But problem is that when I start second thread the first thread gets stops (goes into suspended mode) until socket connection gets over (successful or failure). When I receive true or false from connection the first thread again gets resume. As per the theoretical way these two are separate threads, doing their own job separately. So why they are depends on each other? Even after setting the high priority for first thread it doesn’t work continuously. I am trying this on default emulator. So please help me out to solve this problem. Regards, Krmlkr. |
|
Hello
That's pretty weird... could you post relevant code... maybe showing us how you start the threads... Besides, what emulator are you using? Prioritizing threads doesn't work in all the handsets... it depends on the java implementation of the manufacturer... |
|
Hi rdrincon,
Thanx for your reply. I am posting the relevant code which tell you how I am starting the threads... ************************************************************* public class ThreadDemo extends MIDlet implements CommandListener { public ThreadDemo() { d = Display.getDisplay(this); } protected void startApp() { TCanvas tc = new TCanvas(); Thread t1 = new Thread(tc); t1.setPriority(Thread.MAX_PRIORITY); t1.start(); tc.addCommand(cmdConnect); tc.setCommandListener(this); d.setCurrent(tc); } public void commandAction(Command c, Displayable d) { if(c == cmdConnect) { TConnect tcon = new TConnect(); Thread t2 = new Thread(tcon); t2.setPriority(Thread.MIN_PRIORITY); t2.start(); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } } *********************************************************** In startApp() I am starting first thread of Animation. And on the Command of "Connect" I am starting second thread of socket Connection. For this testing I am using default colorphone from Eclips. Also I have tried it real device. |
|
Hello
Code seems to be ok, there's a similar problem in the herebellow post... maybe it can give you an idea. http://discussion.forum.nokia.com/fo...d.php?t=134058 |
|
TConnect is a extends Runnable class ?
so that when started it actually has a run() method to execute ? |
|
Sorry for that. Here I am adding two other classes...
/***************************************************************/ 1. Class TCanvas shows Animation public class TCanvas extends Canvas implements Runnable { int xCord = 0, yCord = 0; int ballSize = 15; int screenHt = getHeight() - ballSize; int screenW = getWidth() - ballSize; boolean isHitR = true, isHitL = true; boolean isHitU = true, isHitD = true; public TCanvas() { System.out.println("Thread-1 Started..."); } public void paint(Graphics g) { g.setColor(0); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(0,255,0); g.fillArc(xCord, yCord, ballSize, ballSize, 0, 360); } public void run() { while(true) { //...Animation logic try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } repaint(); } } } 2. Class TConnect for Socket connetion public class TConnect implements Runnable { HttpConnection httpConnection; SocketConnection sockConnection; InputStream is = null; public void run() { System.out.println("Thread-2 Started..."); try { sockConnection = (SocketConnection) Connector.open("socket://www.yahoo.com:1234"); } catch (IOException e) { e.printStackTrace(); } } } I think this will help u. Regards, krmlkr. |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Problem with CAknDoubleStyleListBox with a CAknSearchField | jjig | Symbian User Interface | 2 | 2009-09-17 01:58 |
| Problem with eglSwapBuffers and heap corruption | greatape | Symbian Media (Graphics & Sounds) | 2 | 2007-05-24 04:35 |
| netcards - Problem with opening adapter | kernj | Symbian Tools & SDKs | 5 | 2007-01-10 09:56 |
| Problem: S60 SDK for CW in PC with .NET | anttij | Carbide.c++ IDE and plug-ins | 1 | 2005-02-28 12:36 |
| 7210 Silent Problem | MarkMckim | Mobile Java General | 1 | 2003-03-18 13:36 |