「Java」static synchronized メソッドのサンプル
構文
static synchronized void 関数名(){//some code}
スレッドは、synchronizedブロックの開始時にsynchronized文で指定したオブジェクトのロックを取得し、
終了時にそのロックを開放します。
使用例
1.cft.properties
url.user = user01
url.pwd= 2345
2.Javaコード
private static synchronized void initfunc() { try{ ResourceBundle rb = ResourceBundle.getBundle("cft") String user = rb.getString("url.user"); String pwd = rb.getString("db.pwd"); //処理コード } catch(Exception e){ //some code } }