public class LocationPressureTest {
private Todo todo;
private int number;
static Mongo mg = new Mongo("localhost", 27017);
static DB db = mg.getDB("location_pressure_test_db");
static DBCollection col = db.getCollection("location_pressure_test_col");
public interface Todo {
public void doIt();
}
public LocationPressureTest(int number, Todo todo) {
this.number = number;
this.todo = todo;
}
public void start() {
for(int i = 0; i < number; i++) {
new Thread(new Runnable() {
@Override
public void run() {
while(true) {
if(todo != null) {
try {
todo.doIt();
} catch (Throwable t) {
t.printStackTrace();
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}).start();
}
}
/**
* @param args
*/
public static void main(String[] args) {
LocationPressureTest loadRunner = null;
loadRunner = new LocationPressureTest(347, new Todo() {
@Override
public void doIt() {
System.out.println(Thread.currentThread());
col.update(col.findOne(new BasicDBObject("_id", String.valueOf(Math
.round(Math.random() * 5000000)))),
new BasicDBObject("$set", new BasicDBObject("coordinates",
new Double[] { Math.random() * 360 - 180,
Math.random() * 360 - 180 })));
}
});
loadRunner.start();
synchronized (loadRunner) {
try {
loadRunner.wait();
} catch (Exception e) {
}
}
}
}
报错如下
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。