{"id":873,"date":"2022-11-28T20:47:09","date_gmt":"2023-10-29T05:56:26","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/"},"modified":"2025-08-01T03:10:57","modified_gmt":"2025-07-31T18:10:57","slug":"java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/","title":{"rendered":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3"},"content":{"rendered":"<p>Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u306f\u975e\u5e38\u306b\u91cd\u8981\u306a\u30c8\u30d4\u30c3\u30af\u3067\u3059\u3002Java\u306fJava\u30b9\u30ec\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u74b0\u5883\u306e\u30b5\u30dd\u30fc\u30c8\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002\u540c\u4e00\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u4f5c\u6210\u3055\u308c\u305f\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u6570\u3092\u5171\u6709\u3059\u308b\u3053\u3068\u306f\u77e5\u3089\u308c\u3066\u304a\u308a\u3001\u3053\u308c\u306b\u3088\u3063\u3066\u30b9\u30ec\u30c3\u30c9\u304c\u5171\u6709\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u53d6\u308a\u3084\u66f4\u65b0\u306b\u4f7f\u7528\u3055\u308c\u308b\u5834\u5408\u306b\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u304c\u640d\u306a\u308f\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3 (Threading safety)<\/h2>\n<p>\u30c7\u30fc\u30bf\u306e\u4e00\u8cab\u6027\u304c\u306a\u3044\u7406\u7531\u306f\u3001\u4efb\u610f\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u66f4\u65b0\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u304c\u30a2\u30c8\u30df\u30c3\u30af\u306a\u51e6\u7406\u3067\u306f\u306a\u3044\u305f\u3081\u3067\u3059\u3002\u66f4\u65b0\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u307e\u305a\u73fe\u5728\u306e\u5024\u3092\u8aad\u307f\u53d6\u308a\u3001\u6b21\u306b\u66f4\u65b0\u3055\u308c\u305f\u5024\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u5fc5\u8981\u306a\u64cd\u4f5c\u3092\u884c\u3044\u3001\u6700\u5f8c\u306b\u66f4\u65b0\u3055\u308c\u305f\u5024\u3092\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u53c2\u7167\u306b\u5272\u308a\u5f53\u3066\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u5171\u6709\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3059\u308b\u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3053\u308c\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.threads;\r\n\r\npublic class ThreadSafety {\r\n\r\n    public static void main(String[] args) throws InterruptedException {\r\n    \r\n        ProcessingThread pt = new ProcessingThread();\r\n        Thread t1 = new Thread(pt, \"t1\");\r\n        t1.start();\r\n        Thread t2 = new Thread(pt, \"t2\");\r\n        t2.start();\r\n        \/\/wait for threads to finish processing\r\n        t1.join();\r\n        t2.join();\r\n        System.out.println(\"Processing count=\"+pt.getCount());\r\n    }\r\n\r\n}\r\n\r\nclass ProcessingThread implements Runnable{\r\n    private int count;\r\n    \r\n    @Override\r\n    public void run() {\r\n        for(int i=1; i &lt; 5; i++){\r\n            processSomething(i);\r\n        \tcount++;\r\n        }\r\n    }\r\n\r\n    public int getCount() {\r\n        return this.count;\r\n    }\r\n\r\n    private void processSomething(int i) {\r\n        \/\/ processing some job\r\n        try {\r\n            Thread.sleep(i*1000);\r\n        } catch (InterruptedException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n    \r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u3001\u30eb\u30fc\u30d7\u5185\u306e\u30ab\u30a6\u30f3\u30c8\u306f4\u56de\u305a\u30641\u305a\u3064\u5897\u52a0\u3057\u307e\u3059\u3002\u307e\u305f\u30012\u3064\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u3042\u308b\u305f\u3081\u3001\u4e21\u65b9\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u5b9f\u884c\u3092\u5b8c\u4e86\u3057\u305f\u5f8c\u3001\u305d\u306e\u5024\u306f8\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8907\u6570\u56de\u5b9f\u884c\u3059\u308b\u3068\u3001\u30ab\u30a6\u30f3\u30c8\u5024\u304c6\u30017\u30018\u3068\u5909\u52d5\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u6c17\u4ed8\u304f\u3067\u3057\u3087\u3046\u3002\u3053\u308c\u306f\u3001count++\u304c\u30a2\u30c8\u30df\u30c3\u30af\u64cd\u4f5c\u306e\u3088\u3046\u306b\u898b\u3048\u308b\u304c\u3001\u305d\u308c\u306f\u5b9f\u969b\u306b\u306f\u305d\u3046\u3067\u306f\u306a\u304f\u3001\u30c7\u30fc\u30bf\u306e\u7834\u640d\u3092\u5f15\u304d\u8d77\u3053\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u30fc<\/h2>\n<p>Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u74b0\u5883\u3067\u5b89\u5168\u306b\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u30d7\u30ed\u30bb\u30b9\u3067\u3059\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul class=\"post-ul\">\n<li>Synchronization is the easiest and most widely used tool for thread safety in java.<\/li>\n<li>Use of Atomic Wrapper classes from java.util.concurrent.atomic package. For example AtomicInteger<\/li>\n<li>Use of locks from java.util.concurrent.locks package.<\/li>\n<li>Using thread safe collection classes, check this post for usage of ConcurrentHashMap for thread safety.<\/li>\n<li>Using volatile keyword with variables to make every thread read the data from memory, not read from thread cache.<\/li>\n<\/ul>\n<h3>Java\u306esynchronized<\/h3>\n<p>\u540c\u671f\u5316\u306f\u3001\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u30c4\u30fc\u30eb\u3067\u3059\u3002JVM\u306f\u3001\u540c\u671f\u5316\u3055\u308c\u305f\u30b3\u30fc\u30c9\u304c\u4e00\u5ea6\u306b\uff11\u3064\u306e\u30b9\u30ec\u30c3\u30c9\u306b\u3088\u3063\u3066\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u3092\u4fdd\u8a3c\u3057\u307e\u3059\u3002Java\u30ad\u30fc\u30ef\u30fc\u30c9\u306e&#8221;synchronized&#8221;\u306f\u3001\u540c\u671f\u5316\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u3001\u5185\u90e8\u7684\u306b\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u30af\u30e9\u30b9\u306b\u30ed\u30c3\u30af\u3092\u304b\u3051\u3066\u3001\u4e00\u5ea6\u306b\uff11\u3064\u306e\u30b9\u30ec\u30c3\u30c9\u3060\u3051\u304c\u540c\u671f\u5316\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<ul class=\"post-ul\">\n<li>Java synchronization works on locking and unlocking of the resource before any thread enters into synchronized code, it has to acquire the lock on the Object and when code execution ends, it unlocks the resource that can be locked by other threads. In the meantime, other threads are in wait state to lock the synchronized resource.<\/li>\n<li>We can use synchronized keyword in two ways, one is to make a complete method synchronized and another way is to create synchronized block.<\/li>\n<li>When a method is synchronized, it locks the Object, if method is static it locks the Class, so it\u2019s always best practice to use synchronized block to lock the only sections of method that needs synchronization.<\/li>\n<li>While creating a synchronized block, we need to provide the resource on which lock will be acquired, it can be XYZ.class or any Object field of the class.<\/li>\n<li>synchronized(this) will lock the Object before entering into the synchronized block.<\/li>\n<li>You should use the lowest level of locking, for example, if there are multiple synchronized block in a class and one of them is locking the Object, then other synchronized blocks will also be not available for execution by other threads. When we lock an Object, it acquires a lock on all the fields of the Object.<\/li>\n<li>Java Synchronization provides data integrity on the cost of performance, so it should be used only when it\u2019s absolutely necessary.<\/li>\n<li>Java Synchronization works only in the same JVM, so if you need to lock some resource in multiple JVM environment, it will not work and you might have to look after some global locking mechanism.<\/li>\n<li>Java Synchronization could result in deadlocks, check this post about deadlock in java and how to avoid them.<\/li>\n<li>Java synchronized keyword cannot be used for constructors and variables.<\/li>\n<li>It is preferable to create a dummy private Object to use for the synchronized block so that it\u2019s reference can\u2019t be changed by any other code. For example, if you have a setter method for Object on which you are synchronizing, it\u2019s reference can be changed by some other code leads to the parallel execution of the synchronized block.<\/li>\n<li>We should not use any object that is maintained in a constant pool, for example String should not be used for synchronization because if any other code is also locking on same String, it will try to acquire lock on the same reference object from String pool and even though both the codes are unrelated, they will lock each other.<\/li>\n<\/ul>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u30b3\u30fc\u30c9\u306e\u5909\u66f4\u304c\u3053\u3061\u3089\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>    \/\/dummy object variable for synchronization\r\n    private Object mutex=new Object();\r\n    ...\r\n    \/\/using synchronized block to read, increment and update count value synchronously\r\n    synchronized (mutex) {\r\n            count++;\r\n    }\r\n<\/code><\/pre>\n<p>\u3055\u3066\u3001\u3044\u304f\u3064\u304b\u306e\u540c\u671f\u306e\u4f8b\u3092\u898b\u3066\u3001\u305d\u308c\u3089\u304b\u3089\u5b66\u3079\u308b\u3053\u3068\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>public class MyObject {\r\n \r\n  \/\/ Locks on the object's monitor\r\n  public synchronized void doSomething() { \r\n    \/\/ ...\r\n  }\r\n}\r\n \r\n\/\/ Hackers code\r\nMyObject myObject = new MyObject();\r\nsynchronized (myObject) {\r\n  while (true) {\r\n    \/\/ Indefinitely delay myObject\r\n    Thread.sleep(Integer.MAX_VALUE); \r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u30cf\u30c3\u30ab\u30fc\u306e\u30b3\u30fc\u30c9\u306f\u3001myObject\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30ed\u30c3\u30af\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u4e00\u5ea6\u30ed\u30c3\u30af\u3057\u305f\u5f8c\u3001\u89e3\u653e\u3057\u306a\u3044\u305f\u3081\u3001doSomething()\u30e1\u30bd\u30c3\u30c9\u306f\u30ed\u30c3\u30af\u3092\u5f85\u3063\u3066\u30d6\u30ed\u30c3\u30af\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u30b7\u30b9\u30c6\u30e0\u304c\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u72b6\u614b\u306b\u306a\u308a\u3001\u30b5\u30fc\u30d3\u30b9\u306e\u62d2\u5426\uff08DoS\uff09\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>public class MyObject {\r\n  public Object lock = new Object();\r\n \r\n  public void doSomething() {\r\n    synchronized (lock) {\r\n      \/\/ ...\r\n    }\r\n  }\r\n}\r\n\r\n\/\/untrusted code\r\n\r\nMyObject myObject = new MyObject();\r\n\/\/change the lock Object reference\r\nmyObject.lock = new Object();\r\n<\/code><\/pre>\n<p>\u30ed\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3001\u305d\u306e\u53c2\u7167\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u3067\u540c\u671f\u30d6\u30ed\u30c3\u30af\u3092\u4e26\u884c\u3057\u3066\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6301\u3061\u3001\u305d\u306e\u53c2\u7167\u3092\u5909\u66f4\u3059\u308b\u305f\u3081\u306e\u30bb\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308b\u5834\u5408\u3082\u3001\u540c\u69d8\u306e\u30b1\u30fc\u30b9\u304c\u5f53\u3066\u306f\u307e\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>public class MyObject {\r\n  \/\/locks on the class object's monitor\r\n  public static synchronized void doSomething() { \r\n    \/\/ ...\r\n  }\r\n}\r\n \r\n\/\/ hackers code\r\nsynchronized (MyObject.class) {\r\n  while (true) {\r\n    Thread.sleep(Integer.MAX_VALUE); \/\/ Indefinitely delay MyObject\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u30cf\u30c3\u30ab\u30fc\u30b3\u30fc\u30c9\u304c\u30af\u30e9\u30b9\u30e2\u30cb\u30bf\u30fc\u3092\u56fa\u5b9a\u3057\u3066\u89e3\u653e\u3057\u306a\u3044\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30b7\u30b9\u30c6\u30e0\u304c\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u3084DoS\u306b\u9665\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u3001\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u540c\u3058\u6587\u5b57\u5217\u914d\u5217\u3067\u4f5c\u696d\u3057\u3001\u51e6\u7406\u3055\u308c\u305f\u5f8c\u306b\u30b9\u30ec\u30c3\u30c9\u540d\u3092\u914d\u5217\u306e\u5024\u306b\u8ffd\u52a0\u3059\u308b\u5225\u306e\u4f8b\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.threads;\r\n\r\nimport java.util.Arrays;\r\n\r\npublic class SyncronizedMethod {\r\n\r\n    public static void main(String[] args) throws InterruptedException {\r\n        String[] arr = {\"1\",\"2\",\"3\",\"4\",\"5\",\"6\"};\r\n        HashMapProcessor hmp = new HashMapProcessor(arr);\r\n        Thread t1=new Thread(hmp, \"t1\");\r\n        Thread t2=new Thread(hmp, \"t2\");\r\n        Thread t3=new Thread(hmp, \"t3\");\r\n        long start = System.currentTimeMillis();\r\n        \/\/start all the threads\r\n        t1.start();t2.start();t3.start();\r\n        \/\/wait for threads to finish\r\n        t1.join();t2.join();t3.join();\r\n        System.out.println(\"Time taken= \"+(System.currentTimeMillis()-start));\r\n        \/\/check the shared variable value now\r\n        System.out.println(Arrays.asList(hmp.getMap()));\r\n    }\r\n\r\n}\r\n\r\nclass HashMapProcessor implements Runnable{\r\n    \r\n    private String[] strArr = null;\r\n    \r\n    public HashMapProcessor(String[] m){\r\n        this.strArr=m;\r\n    }\r\n    \r\n    public String[] getMap() {\r\n        return strArr;\r\n    }\r\n\r\n    @Override\r\n    public void run() {\r\n        processArr(Thread.currentThread().getName());\r\n    }\r\n\r\n    private void processArr(String name) {\r\n        for(int i=0; i &lt; strArr.length; i++){\r\n            \/\/process data and append thread name\r\n            processSomething(i);\r\n            addThreadName(i, name);\r\n        }\r\n    }\r\n    \r\n    private void addThreadName(int i, String name) {\r\n        strArr[i] = strArr[i] +\":\"+name;\r\n    }\r\n\r\n    private void processSomething(int index) {\r\n        \/\/ processing some job\r\n        try {\r\n            Thread.sleep(index*1000);\r\n        } catch (InterruptedException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n    \r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>Time taken= 15005\r\n[1:t2:t3, 2:t1, 3:t3, 4:t1:t3, 5:t2:t1, 6:t3]\r\n<\/code><\/pre>\n<p>\u6587\u5b57\u5217\u306e\u914d\u5217\u306e\u5024\u306f\u3001\u5171\u6709\u30c7\u30fc\u30bf\u3068\u540c\u671f\u306e\u6b20\u5982\u306e\u305f\u3081\u306b\u7834\u640d\u3057\u3066\u3044\u307e\u3059\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3059\u308b\u305f\u3081\u306b\u3001addThreadName() \u30e1\u30bd\u30c3\u30c9\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>    private Object lock = new Object();\r\n    private void addThreadName(int i, String name) {\r\n        synchronized(lock){\r\n        strArr[i] = strArr[i] +\":\"+name;\r\n        }\r\n    }\r\n<\/code><\/pre>\n<p>\u3053\u306e\u5909\u66f4\u5f8c\u3001\u79c1\u305f\u3061\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u3001\u4ee5\u4e0b\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u6b63\u3057\u3044\u51fa\u529b\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>Time taken= 15004\r\n[1:t1:t2:t3, 2:t2:t1:t3, 3:t2:t3:t1, 4:t3:t2:t1, 5:t2:t1:t3, 6:t2:t1:t3]\r\n<\/code><\/pre>\n<p>\u305d\u308c\u304cJava\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u306b\u3064\u3044\u3066\u306e\u5168\u3066\u3067\u3059\u3002\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3068synchronized\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u4f7f\u7528\u306b\u3064\u3044\u3066\u5b66\u3079\u305f\u3053\u3068\u3092\u9858\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u306f\u975e\u5e38\u306b\u91cd\u8981\u306a\u30c8\u30d4\u30c3\u30af\u3067\u3059\u3002Java\u306fJava\u30b9\u30ec\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u74b0\u5883\u306e\u30b5\u30dd\u30fc\u30c8\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002\u540c\u4e00\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u4f5c\u6210\u3055\u308c\u305f\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u6570\u3092\u5171\u6709\u3059\u308b\u3053\u3068 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,61],"class_list":["post-873","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-26","tag-61"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/ja\/blog\/java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\" \/>\n<meta property=\"og:description\" content=\"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-29T05:56:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T18:10:57+00:00\" \/>\n<meta name=\"author\" content=\"\u512a\u6597, \u671d\u967d\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u512a\u6597, \u671d\u967d\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"18\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/\",\"name\":\"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2023-10-29T05:56:26+00:00\",\"dateModified\":\"2025-07-31T18:10:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cab7534c71201607a41f395de14d7d28\"},\"description\":\"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cab7534c71201607a41f395de14d7d28\",\"name\":\"\u512a\u6597, \u671d\u967d\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/56ecb1d20648a2ff67709eeaa7b6eddeb4d52aca0d46febc7f12bbef507187d0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/56ecb1d20648a2ff67709eeaa7b6eddeb4d52aca0d46febc7f12bbef507187d0?s=96&d=mm&r=g\",\"caption\":\"\u512a\u6597, \u671d\u967d\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/yutoasahi\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3 - Blog - Silicon Cloud","description":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/ja\/blog\/java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\/","og_locale":"ja_JP","og_type":"article","og_title":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3","og_description":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-10-29T05:56:26+00:00","article_modified_time":"2025-07-31T18:10:57+00:00","author":"\u512a\u6597, \u671d\u967d","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u512a\u6597, \u671d\u967d","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"18\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/","name":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2023-10-29T05:56:26+00:00","dateModified":"2025-07-31T18:10:57+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cab7534c71201607a41f395de14d7d28"},"description":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"Java\u306b\u304a\u3051\u308b\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u30c6\u30a3"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cab7534c71201607a41f395de14d7d28","name":"\u512a\u6597, \u671d\u967d","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/56ecb1d20648a2ff67709eeaa7b6eddeb4d52aca0d46febc7f12bbef507187d0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/56ecb1d20648a2ff67709eeaa7b6eddeb4d52aca0d46febc7f12bbef507187d0?s=96&d=mm&r=g","caption":"\u512a\u6597, \u671d\u967d"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/yutoasahi\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e3%82%b9%e3%83%ac%e3%83%83%e3%83%89%e3%82%bb%e3%83%bc%e3%83%95%e3%83%86%e3%82%a3\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=873"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/873\/revisions"}],"predecessor-version":[{"id":46080,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/873\/revisions\/46080"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}