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: 296
Registered: ‎12-07-2008
My Device: Not Specified

Thread question

I have an app where I will need a thread to run and stop at different times.

 

My question is would it be better to keep setting up my thread when I need it, or would it be better to haev the thread sleep and then intterupt it when I need it?

 

I've been trying to find the answer online but haven't found anything. I would imagine that a sleeping thread uses very little system reoures if at all. Howerver recreating the thread over and over again could be a strain on resources.

 

I'm just wondering because it isn't clear to me what the better option would be.

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: Thread question

well i think it depends upon your requirement

 

if you need to work frequently inside the thread then i think u should create a single thread and put it to sleep when not required

 

Highlighted
Developer
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Thread question

I'm guess what I'm wondering is what takes up more system resources putting a thread to sleep and interrupting it or creating and destroying the thread.

 

Is there any real downside to keeing the thread alive and sleeping it rather then killing the thread and having to recreate the thread? I only have 2 threads in the whole app so it's not like I will have too many threads exception or anything like that. I'm just not sure if there are any side effects to a sleeping thread.

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Thread question

The biggest thing to think about is how often you will need to wake the thread and whether or not you know exactly when you need the tread working or if it is dynamic. If you have widly varying constraints then it would not be very reasonable to have to keep polling the thread because then it is effect constantly running.

Developer
Posts: 374
Registered: ‎04-07-2010
My Device: Bold 9000
My Carrier: Airtel

Re: Thread question

I would suggest that... If you want to use that thread after short intervals(quite often) go for sleeping it... but if the interval is long and less frequent go for killing it and recreating it....

Press the Like button (Thumb up) on the left side to thank and
please mark the Thread as solved if its solved...
K.S
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Thread question

If the thread is only used to periodically invoke very short operations, consider using the event thread instead (Application.invokeLater with the specified time/periodicity to invoke the Runnable).