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
Contributor
Posts: 35
Registered: ‎06-14-2010
My Device: Blackberry Curve 8530
My Carrier: Telcel

Blackberry thread hanging on SQLite statement prepare

Hi Gurus.

I'm developing an application that implements an EditField in which you can type a word and while typing the application will filter the contents that are being shown on screen.

For this, I'm starting a new thread when the user types. This thread extracts the information from a SQLite table and then shows it on the UI.

I use SQLite for other things in the application and every statement works great.

THE PROBLEM is that when I use the Statement.prepare() method in the Filtering thread, it hangs!

To make this simpler, lets suppose the user only typed 1 letter in the EditField.

The idea of the code is something like this:

I start the thread after the user typed a letter:

            mThread = new Thread(){                 
                 
public void run(){filtrarListaRecolecciones();}                    
           
};
            mThread
.setPriority(Thread.MAX_PRIORITY);
            mThread
.start();

And at filtrarListaRecolecciones I run:

mStatement = mBD.createStatement("SELECT COUNT(*) FROM Recolecciones WHERE Nombre LIKE '%a%' AND Status=3");
mStatement
.prepare();

And the thread hangs at the prepare statement.

It used to get the result after about 1 minute but now it just hangs.

The table has only 1 record so it shouldn't be because of that.

Any help would be greatly appreciated!

Thanks!

Developer
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700
My Carrier: Vodafone UK

Re: Blackberry thread hanging on SQLite statement prepare

[ Edited ]

I'm not sure but maybe the MAX_PRIORITY could be an issue by hogging resources?

 

does it need it's own thread?

 

Why not try putting the method call in a Runnable and calling invokeLater?

 

Sample:

 

Runnable callMethod = new Runnable() {
	public void run() {
		// Call your method
	}
};

UiApplication.getUiApplication.invokeLater(callMethod);

 

Hope this helps!

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry thread hanging on SQLite statement prepare

I have to disagree with the suggestion made by geeneeus. 

 

You should not do this using invokeLater.  This is a potentially blocking operation and must be done on its own Thread.

 

ANyway I have been waiting for other input because I wanted to see if other people had this.  I think I've seen it, but did not do the indepth analysis that you did. 

 

I see the following from time to time on the old 9550 Simulator I have and I used to see it on my Storm 2 9520, until I upgraded the OS.  But not on my 9700. 

 

Basically the first time SQL is used it seems to hang waiting for something.  Sometimes after the hang it doesn't work at all.  However if you stop the app and restart, it kicks in OK.  Once it has kicked in, it works fine until you re-install. 

 

Do you think we have seen the same problem?

 

Ah yes one other thing, I tried making the SQL Thread PRIORITY_MIN, that actually seemed to make it worse.  So I put it back.  

Contributor
Posts: 35
Registered: ‎06-14-2010
My Device: Blackberry Curve 8530
My Carrier: Telcel

Re: Blackberry thread hanging on SQLite statement prepare

Hi

 

I also agree with using a different Thread instead of invokeLater since I'm consuming 2 web services in this step Smiley Tongue

 

Peter, I'm think it's the same problem. It show randomly, sometimes it does, sometimes it doesn't but now it's showing up a lot!, I'm running it on the 9700 simulator.

 

Is this a Simulator issue only then?

Will it work ok on a phone?

 

I think I tested it on my friend's 9700 and didn't work =/

 

Thanks you!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry thread hanging on SQLite statement prepare

Never seen it on a 9700 device.  have seen it on a 9520, but with old OS level.  I suspect this is bug that has been fixed.  It is pretty random (but extremely annoying). 

 

What level SImualtor are you using?

Contributor
Posts: 35
Registered: ‎06-14-2010
My Device: Blackberry Curve 8530
My Carrier: Telcel

Re: Blackberry thread hanging on SQLite statement prepare

Not sure what you mean by level of simulator but it's this one:

 

Backberry-SDK 9700

Blackberry JRE 5.0.0

 

is this what you were talking about?

 

Thanks

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry thread hanging on SQLite statement prepare

Once the SImualtor is up, using Options-->About.

Contributor
Posts: 35
Registered: ‎06-14-2010
My Device: Blackberry Curve 8530
My Carrier: Telcel

Re: Blackberry thread hanging on SQLite statement prepare

BlackBerry 9700

Smartphone (3G-WiFi)

v5.0.0.535 (Platform 2.13.0.108)

Cryptographic Kernel: v3.8.5.85

Branding version: 1.0.255.211A

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry thread hanging on SQLite statement prepare

That is more current than mine.  I think this might be a bug to put in issue tracker, especially if you can create a simple example that shows it. 

Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: Blackberry thread hanging on SQLite statement prepare

I have exactly the problem you are talking about. Did you find any solution/conclusion about it?