g*g
2 楼
我试图多线程处理一个Queue上的数据,数据是一个email address和一些相关
数据。email address作为用户名,在DB里必须是unique的。我多线程处理
这些用户的时候,产生的问题是多个线程都试图建立同一个用户,这时候
后commit的线程就会出错。怎么才可以避免这个问题而又尽量保持性能呢?
我用的是hibernate和spring.
数据。email address作为用户名,在DB里必须是unique的。我多线程处理
这些用户的时候,产生的问题是多个线程都试图建立同一个用户,这时候
后commit的线程就会出错。怎么才可以避免这个问题而又尽量保持性能呢?
我用的是hibernate和spring.
A*o
4 楼
get an email based schedule?
e*6
9 楼
欢迎版主回来。。。
最近好像版上热闹起来了呢。。。
最近好像版上热闹起来了呢。。。
g*g
10 楼
I am thinking something like this
if(user doesn't exist) {
synchronize(address.intern()) {
transaction begins;
if(user doesn't exist) {
create user
}
transaction ends;
}
}
// process user
Any better idea?
【在 g*****g 的大作中提到】
: 我试图多线程处理一个Queue上的数据,数据是一个email address和一些相关
: 数据。email address作为用户名,在DB里必须是unique的。我多线程处理
: 这些用户的时候,产生的问题是多个线程都试图建立同一个用户,这时候
: 后commit的线程就会出错。怎么才可以避免这个问题而又尽量保持性能呢?
: 我用的是hibernate和spring.
if(user doesn't exist) {
synchronize(address.intern()) {
transaction begins;
if(user doesn't exist) {
create user
}
transaction ends;
}
}
// process user
Any better idea?
【在 g*****g 的大作中提到】
: 我试图多线程处理一个Queue上的数据,数据是一个email address和一些相关
: 数据。email address作为用户名,在DB里必须是unique的。我多线程处理
: 这些用户的时候,产生的问题是多个线程都试图建立同一个用户,这时候
: 后commit的线程就会出错。怎么才可以避免这个问题而又尽量保持性能呢?
: 我用的是hibernate和spring.
f*e
11 楼
要过节了,百鬼夜行阿
c*t
12 楼
This is probably the best you can get, which is the check-and-check-again
paradigm.
Depending on your collision frequency, other approaches may exist. Mostly
dealing with some sort of cache.
【在 g*****g 的大作中提到】
: I am thinking something like this
: if(user doesn't exist) {
: synchronize(address.intern()) {
:
: transaction begins;
: if(user doesn't exist) {
: create user
: }
: transaction ends;
: }
paradigm.
Depending on your collision frequency, other approaches may exist. Mostly
dealing with some sort of cache.
【在 g*****g 的大作中提到】
: I am thinking something like this
: if(user doesn't exist) {
: synchronize(address.intern()) {
:
: transaction begins;
: if(user doesn't exist) {
: create user
: }
: transaction ends;
: }
g*g
16 楼
That doesn't sound right. I don't want to create a new
user (which will result an error), but I do want to create
some new records that are associated with the user in
each thread. And I want them to be created as fast as possible.
Let's say if you have 10 messages coming in all for a new
user. You want to create a user record, and 10 message records
associated with this user. Obviously if you have 10 threads.
The fastest way is to create a user and commit, then all 10
threads create message rec
【在 k***r 的大作中提到】
: Use hash value to partition users to a specific thread?
user (which will result an error), but I do want to create
some new records that are associated with the user in
each thread. And I want them to be created as fast as possible.
Let's say if you have 10 messages coming in all for a new
user. You want to create a user record, and 10 message records
associated with this user. Obviously if you have 10 threads.
The fastest way is to create a user and commit, then all 10
threads create message rec
【在 k***r 的大作中提到】
: Use hash value to partition users to a specific thread?
k*r
17 楼
I assumed the DB was the bottleneck in a lot of cases so
having multiple threads hitting the DB wouldn't help. I also
assumed that the messages coming in were somewhat random
in terms of user name. However both of my assumption could
be false, and it sounds like they are false in your case.
If this is the case, the double-checked lock pattern seems
to be the way to go.
【在 g*****g 的大作中提到】
: That doesn't sound right. I don't want to create a new
: user (which will result an error), but I do want to create
: some new records that are associated with the user in
: each thread. And I want them to be created as fast as possible.
: Let's say if you have 10 messages coming in all for a new
: user. You want to create a user record, and 10 message records
: associated with this user. Obviously if you have 10 threads.
: The fastest way is to create a user and commit, then all 10
: threads create message rec
having multiple threads hitting the DB wouldn't help. I also
assumed that the messages coming in were somewhat random
in terms of user name. However both of my assumption could
be false, and it sounds like they are false in your case.
If this is the case, the double-checked lock pattern seems
to be the way to go.
【在 g*****g 的大作中提到】
: That doesn't sound right. I don't want to create a new
: user (which will result an error), but I do want to create
: some new records that are associated with the user in
: each thread. And I want them to be created as fast as possible.
: Let's say if you have 10 messages coming in all for a new
: user. You want to create a user record, and 10 message records
: associated with this user. Obviously if you have 10 threads.
: The fastest way is to create a user and commit, then all 10
: threads create message rec
m*t
18 楼
So create the user first, then you are free to do the rest concurrently
and independently without synchronization.
【在 g*****g 的大作中提到】
: That doesn't sound right. I don't want to create a new
: user (which will result an error), but I do want to create
: some new records that are associated with the user in
: each thread. And I want them to be created as fast as possible.
: Let's say if you have 10 messages coming in all for a new
: user. You want to create a user record, and 10 message records
: associated with this user. Obviously if you have 10 threads.
: The fastest way is to create a user and commit, then all 10
: threads create message rec
and independently without synchronization.
【在 g*****g 的大作中提到】
: That doesn't sound right. I don't want to create a new
: user (which will result an error), but I do want to create
: some new records that are associated with the user in
: each thread. And I want them to be created as fast as possible.
: Let's say if you have 10 messages coming in all for a new
: user. You want to create a user record, and 10 message records
: associated with this user. Obviously if you have 10 threads.
: The fastest way is to create a user and commit, then all 10
: threads create message rec
相关阅读
请问同时执行几个bat文件的问题也来问一个Runtime.getRuntime().exec的问题JTabbedPane的一个问题EJB book做J2EE的大侠们,能推荐一下比较好用的referrence website吗?Java Reflection Performance 测验which http client package is good to use?Help: how to use Eclipse as C++ IDE in Linux?Simple question: delete element from collection on condition?Textfield auto tab-traversal如何安装Geronimo?网页的Form中Post的问题 (转载)祝java版的各位同修关于java执行SQL之后的内存问题?想找几个模板Java虚拟磁盘问题请教:怎样函数里改变一个Double变量的值?请教一个简单的问题请问如何避免这样的styleJRE的DNS怪现象