BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-23-2008, 01:46 PM   #1
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default HOW TO INITIATE HttpConnection AT INTERVALS

Please Login to Remove!

I am trying to initiate HttpConnection at every 1min (or whatever interval the user supplies) but the thread.sleep() method I am using causes the whole phone to freeze for 1min instead of spacing the recursive HttpConnection call by 1min.


-----------------------------
private void getInterval()
{
_sleepThread.run();
fetchStock();
getInterval();
}
----------------------------
private static class SleepThread extends Thread
{
public void run()
{
try {
sleep(60000); }
catch ( InterruptedException e) {}
}
}
----------------------------

The fetchStock() method calls the HttpConnection method in another private thread class which retreives the webpage, retrieval is synchrozied to prevent another call being made while the previous one is still working.

The BlackBerry freezes whenever i call "_sleepThread.run()" from getInterval() method in the main class of the application.

Is there another way to pause the recursive getInterval() method for a particular interval?
Offline  
Old 06-23-2008, 01:51 PM   #2
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default

The BlackBerry becomes unresponsive to any keypad input for exactly the amount of milli-seconds specified in the thread.sleep(TIME) method, then goes on to execute the HttpConnection request.

I dont want the BB to freeze, I only want to pause the recursive call.

What am I doing wrong?
Offline  
Old 06-23-2008, 04:24 PM   #3
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Are you ever unwinding that recursion? You'll run out of stack eventually if you don't.

Anyway, you're treating SleepThread like a Runnable instead of a Thread. Use "start" instead of "run".
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-23-2008, 09:36 PM   #4
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default

Quote:
Originally Posted by richard.puckett View Post
Are you ever unwinding that recursion? You'll run out of stack eventually if you don't.

Anyway, you're treating SleepThread like a Runnable instead of a Thread. Use "start" instead of "run".

Thx for the response, this is my first BlackBerry application so I am not yet very familiar with the syntaxes.

How do I unwind the recursion?
Where am I to change "run" to start? In class SleepThread or I should change the calling method from _sleepThread.run() to _sleepThread.start()?
Offline  
Old 06-23-2008, 11:01 PM   #5
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Maybe you should look into Timer and TimerTask. Schedule your http connection to occur on an interval. That will take care of a lot of the dirty work for you. Concurrency *and* mobile is kind of a big intro to Java programming.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-27-2008, 10:49 AM   #6
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default

Thx richard, Timer/TimerTask did the trick though I had to create an additional "runnable" thread class that calls the timer class.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Fanuc Motherboard A16B-3200-0429/07B picture

Fanuc Motherboard A16B-3200-0429/07B

$674.25



1PCS FANUC System Motherboard A20B-8100-0662 picture

1PCS FANUC System Motherboard A20B-8100-0662

$1697.00



ABB ACS880 motherboard ZCU-14 3AXD5000005164 1PCS picture

ABB ACS880 motherboard ZCU-14 3AXD5000005164 1PCS

$990.00



ABB control motherboard 3BHE024855R0101 UF C921 A101 picture

ABB control motherboard 3BHE024855R0101 UF C921 A101

$2160.00



ONE New EMB-H110B ITX Industrial Motherboard USB 3.0 #E5 picture

ONE New EMB-H110B ITX Industrial Motherboard USB 3.0 #E5

$395.15



Used & Tested IPC PCI-6870F Motherboard picture

Used & Tested IPC PCI-6870F Motherboard

$255.11







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.