在main方法中,子线程使用java 1.5执行器服务机制启动.如何使主线程等到子线程完成?
public class MainClass {
public static void main(String[] args) {
ExecutorService executorService=null;
try {
executorService=Executors.newFixedThreadPool(1);
executorService.execute(new TestThread());
System.out.println("Main program exited...");
} catch (Exception e) {
e.printStackTrace();
} finally {
executorService.shutdown();
}
}
}
public class TestThread extends Thread {
public TestThread() {
}
public void run() {
try {
for (int i=0;i<10;i++) {
System.out.println(i);
TimeUnit.SECONDS.sleep(5);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有两个线程.每个线程与不同的外部实体通信.
让我们说T1 - > N1和T2 - > N2(T1和T2是两个线程.N1和N2是外部实体.通信是基于HTTPS的SOAP.)
N1的供应商要求使用密钥存储文件UPCC_client.store进行身份验证,同样我们使用了以下代码,
System.setProperty("javax.net.ssl.keyStore", "<file path>");
System.setProperty("javax.net.ssl.keyStorePassword", "<password>");
System.setProperty("javax.net.ssl.trustStore","<file path>");
System.setProperty("javax.net.ssl.trustStorePassword", "<password>");
Run Code Online (Sandbox Code Playgroud)
已使用T1线程中设置的上述属性重新启动应用程序,没有任何问题.T2开始遇到麻烦,因为T1设置的属性被T2使用.这背后的主要原因System.setProperty是JVM范围.如何解决这个问题?
我们有一个配置,其中每个属性映射到DB中的两个值,
例如:
Property Name Min Value Max Value
VSMSSUB 100 500
EEVMSSUB 100 500
Run Code Online (Sandbox Code Playgroud)
现在,可以使用哪些集合来存储房产以及最小值和最大值?HashMap是不可能的,因为它是一对一的.
要么
我可以这样声明吗?
HashMap中
要么
需要用豆子吗?
请提出您的建议.