You Are Here:

Community: Developer Discussion Boards

#1 Old Thumbs up Problem in threading operation... - 2008-05-23, 07:55

Join Date: Jan 2008
Posts: 10
krmlkr
Offline
Registered User
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.
Reply With Quote

#2 Old Re: Problem in threading operation... - 2008-05-23, 15:56

Join Date: May 2007
Posts: 347
Location: Mexico D.F
rdrincon's Avatar
rdrincon
Offline
Forum Nokia Expert
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...
Reply With Quote

#3 Old Thumbs up Re: Problem in threading operation... - 2008-05-26, 07:55

Join Date: Jan 2008
Posts: 10
krmlkr
Offline
Registered User
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.
Reply With Quote

#4 Old Re: Problem in threading operation... - 2008-05-27, 06:51

Join Date: May 2007
Posts: 347
Location: Mexico D.F
rdrincon's Avatar
rdrincon
Offline
Forum Nokia Expert
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
Reply With Quote

#5 Old Re: Problem in threading operation... - 2008-05-27, 09:21

Join Date: Apr 2007
Posts: 1,757
Tiger79's Avatar
Tiger79
Offline
Forum Nokia Champion
TConnect is a extends Runnable class ?
so that when started it actually has a run() method to execute ?
Reply With Quote

#6 Old Thumbs up Re: Problem in threading operation... - 2008-05-28, 11:20

Join Date: Jan 2008
Posts: 10
krmlkr
Offline
Registered User
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia