• Post Reply Bookmark Topic Watch Topic
  • New Topic

stateless ejb concurrency  RSS feed

 
Cedric Bosch
Ranch Hand
Posts: 99
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting 2 questions at once, but I've 2 that are blocking me so..
I've read the oracle guide on concurrency (https://docs.oracle.com/javaee/7/tutorial/persistence-locking001.htm) but I'm still unsure of what happens if an user makes a query and another is taking place at the same time.
I've an @schedule method that updates row in my database. For 120k rows it takes about 6 seconds. I would like to know what happens if an user tries to edit one of the row during that process? Does he have to wait 6 seconds ? I didn't specify a locking mode.

the method is like this:

 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't about concurrency, this is about locking. And even though you didn't specify any locking, you may still be troubled by it. For instance, MS SQL Server by default locks tables during updates. If that update takes 6 seconds, then yes, your search will be waiting for 6 seconds.
 
Cedric Bosch
Ranch Hand
Posts: 99
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:This isn't about concurrency, this is about locking. And even though you didn't specify any locking, you may still be troubled by it. For instance, MS SQL Server by default locks tables during updates. If that update takes 6 seconds, then yes, your search will be waiting for 6 seconds.


Well that's disappointing. I actually update my Threads table every minute because the hot score (like the reddit algorithm) of every thread changes with time. So if I understand correctly, that means that every minute an user who wants to access the top 100 threads (which are the threads which have the TOP hot score) then that visitor is gonna have to wait 6 seconds. I wonder how they have done it over there on reddit.

Though it's not the update that takes 6 seconds, it's the whole process from getting the list of all threads, modifying the score and then saving it again. So I guess I can split that in 3 so there is no locking for 6 seconds. I'm not sure I know how all this works so I'm just taking a guess here.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are ways to turn off locking, at least for reads. In SQL Server you can use "WITH (NOLOCK)" in SELECT queries, which means that the SELECT queries aren't blocked by any other transactions but may get stale data.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you should be aware that non-locking reads (dirty reads) may not show the most recent values for the record.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I meant with stale data.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!