1
|
import java.util.ArrayList;
|
2
|
import java.util.List;
|
3
|
import com.mongodb.MongoClient;
|
4
|
import com.mongodb.MongoClientOptions;
|
5
|
import com.mongodb.ReadPreference;
|
6
|
import com.mongodb.ServerAddress;
|
7
|
|
8
|
public class Test {
|
9
|
public static void main(String[] args) {
|
10
|
System.out.println("starting!!!");
|
11
|
Test.test();
|
12
|
System.out.println("end!!!");
|
13
|
}
|
14
|
|
15
|
public static void test(){
|
16
|
MongoClient mongoClient = null;
|
17
|
MongoClientOptions options = null;
|
18
|
List<ServerAddress> serverList = null;
|
19
|
try {
|
20
|
serverList = new ArrayList<ServerAddress>();
|
21
|
serverList.add(new ServerAddress("localhost"));
|
22
|
options = new MongoClientOptions.Builder().readPreference(ReadPreference.secondary())
|
23
|
.maxConnectionIdleTime(1)
|
24
|
.maxConnectionLifeTime(1)
|
25
|
.build();
|
26
|
mongoClient = new MongoClient (serverList, options);
|
27
|
} catch (Exception exception) {
|
28
|
exception.printStackTrace();
|
29
|
}
|
30
|
|
31
|
}
|
32
|
}
|