If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
jppedroso
Posts: 119
Registered: ‎04-29-2010
My Device: Curve 8520
My Carrier: TMN

http connection thread with timer ?

Hi,

I have a class(GetHTTPData) that implements a thread wich makes a http connection to update data on recordstore.

I want to launch this thread every minute.

How should I do it? with a Timer launching GetHTTPData?

................................................................................................
Tech On!
PTNews
more at On On On!
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: http connection thread with timer ?

That should work.

 

Every minute seems like quite a lot.  Would push be a better solution?

Please use plain text.
Trusted Contributor
jppedroso
Posts: 119
Registered: ‎04-29-2010
My Device: Curve 8520
My Carrier: TMN

Re: http connection thread with timer ?

Hi Peter,

 

As I'm newbie on java I'm afraid to launch a bunch of threads and shutdown the app.

As far as I know the timer itself creates a new thread and it will launch a new thread every minute.

What are the measures that I must take in order to guarantee the App stability?

 

thks

................................................................................................
Tech On!
PTNews
more at On On On!
Please use plain text.
Trusted Contributor
KraKra
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Re: http connection thread with timer ?

why don't you use a single thread, which fetches data periodically

 

while (shouldStop)

{

//  get data

// sleep some time

}

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: http connection thread with timer ?

While I agree with KraKra, and in fact that is probably how I would do it, if your Thread is going to finish in a minute, there will only ever be one outstanding.  So not really a problem. 

 

From memory you can catch the "Too many Threads" Exception on the start anyway if you see it. 

 

But my biggest issue with this is the need to start networking activity every minute.  That sounds like polling and polling is bad for battery life and typically bad for overuse of network data.  So I would review this design approach. 

Please use plain text.
Trusted Contributor
jppedroso
Posts: 119
Registered: ‎04-29-2010
My Device: Curve 8520
My Carrier: TMN

Re: http connection thread with timer ?

I don´t know how long will last the Thread. I assume that the operation sometimes could take longer, and then I could have several threads on execution.

 

I saw on another post that the While loop is not time accurate...that was the fact that lead me to use a Timer...

 

Peter, if you had to call a WebService that querys a Database wich is being upgraded at every second, and you wanted to refresh your app with new data, how would you do that?

 

Thks a lot for your help!

................................................................................................
Tech On!
PTNews
more at On On On!
Please use plain text.