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
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Using sqlite from multiple threads(design pattern)

Two threads A & B  run in background, during splash screen, ThreadA and ThreadB fetches data from 2 different URLs parse it and insert into database in tableA and tableB. I created one synchronized method for creating database object. At times the object is created for both the thread, but at times one thread is getting the object while other is getting null. 

 

private synchronized Database accessDB()
	{
		if(dbObj==null)
		{
		try {
			_uri = URI.create(dbLocation + DB_NAME);
	        try {
				dbObj = DatabaseFactory.openOrCreate(_uri, new DatabaseSecurityOptions(false));
				System.out.println("Database Created"+_dbTopNews);
	        } catch (ControlledAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (DatabaseIOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (DatabasePathException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURIException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		return dbObj;
	}

 A Y

 

Highlighted
New Member
Posts: 1
Registered: ‎01-16-2012
My Device: 9300
My Carrier: Vodafone

Re: Using sqlite from multiple threads(design pattern)

you can do this but in concurrent threading that's can be done by creating Database engine