db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Waagan <Kristian.Waa...@Sun.COM>
Subject Re: threads and derby
Date Thu, 17 Apr 2008 18:08:20 GMT
Brandon Dohman skrev:
> To answer your question, can you elaborate on how you access your database?
> For instance:
>  a) Are you using a single or multiple connections?
>
> -- I'm using just one server to connect to the database.  All transactions on the database
will go through this server, nothing else will have access to it.
>   

That still doesn't answer my question, so more information is required.
Assuming you are using DriverManager to obtain your connections (you 
could also be using a DataSource or a framework on top of JDBC), how 
many getConnection() calls are you issuing?
If you share a single connection to the database between your Java 
threads, you might have to synchronize access to it yourself. This is 
especially true if autocommit is disabled.
Normally, it would be better to create multiple connections to the 
database, but you have to consider this in light of your application 
context.

Also, are you accessing Derby through the embedded or the client driver?

>  b) Is autocommit used, or are you committing your transactions explicitly?
> -- In regards to this question I'm unsure of which I am using, as I haven't came across
this before.  I'm still fairly new to java and derby so I am not sure exactly what I would
be using.  Basically my process was to install derby, then setup my username/password and
all my tables through netbeans.  If there is more setup process that needs to be done, I haven't
come across it yet.
>   

Okay. The default for Derby is to use autocommit, which in effect causes 
each query / operation towards the database to be a separate transaction.
If you want to read more on transactions and autocommit, just search for 
a JDBC tutorial / introduction.

This is still a bit in the blue, but hopefully it should give you 
something to work on :)


-- 
Kristian

>
>
> -----Original Message-----
> From: Kristian.Waagan@Sun.COM [mailto:Kristian.Waagan@Sun.COM] 
> Sent: Thursday, April 17, 2008 12:32 PM
> To: Derby Discussion
> Subject: Re: threads and derby
>
> Brandon Dohman skrev:
>   
>> I’ve currently created a multithreaded server that is using 1 class to 
>> do all of the database interactions when receiving commands from the 
>> client programs.
>>
>>  
>>
>> My question:  When my server code has multiple threads going, will the 
>> database, or the java code for that matter, wait until the current 
>> threads transactions are done before allowing another thread to take 
>> control of the database?
>>
>>  
>>
>> I have created a simple user login system that allows access to a 
>> machine, and there will be possible multiple logins going on at the 
>> same time (very possible it will never happen at the exact same time) 
>> but along with logins, admin users will be updating information in the 
>> database.  And I just want to make sure I won’t crash my database, if 
>> I have operations trying to access things at the same time.
>>
>>     
> Hello Brandon,
>
> In general, Derby is thread safe and supports multiple connections / users.
> Concurrent accesses will be synchronized internally to avoid data 
> corruption and other problems.
>
> To answer your question, can you elaborate on how you access your database?
> For instance:
>  a) Are you using a single or multiple connections?
>  b) Is autocommit used, or are you committing your transactions explicitly?
>
> If you answer these questions, I'm sure you will get more feedback.
>
>
> regards,
>   


Mime
View raw message