IBM Developer is your one-stop location for getting hands-on training and learning in-demand skills on relevant technologies such as generative AI, data science, AI, and open source.
Vï¼ï¼java1.4.2 OSï¼WindowsXp ãã«ãã¹ã¬ããã®ããã°ã©ã ã§ãä¸ã¤ã®ãã¡ã¤ã«ã«ããã¹ãã®åºåãè¡ãã¨ããã§ããã¾ããããªãã¨ãããããã¾ãã ï¼ã½ã¼ã¹ãã¡ã¤ã«ï¼ import java.io.*; import java.util.*; import java.text.*; public class ThreadIppai { public static void main(String[] args) { for (int i = 0; i < 100; i++) { Thread thread = new ThreadHontai(); thread.start(); } } } class ThreadHontai extends Thread { public void run() { try { for (int i = 0; i < 500; i++) {
ä¸ã¤ã®Javaããã°ã©ã ã«ã¤ãã¦ãå¦çããã«ãã¹ã¬ããã§ä¸¦è¡æ§ãæã¤ããã«è¨è¿°ããè¤æ°CPUï¼ãã«ãã³ã¢ï¼ä¸ã§ãã®ããã°ã©ã ãå®è¡ãããã¨ã«ãã並åå¦çãå®ç¾ãããã¨ããéããã°åºåãå®è¡æ§è½ã«ã©ãã ãå½±é¿ãåã¼ãã®ããææ¡ããããã¨èãã¦ãã¾ãã ããã°ã©ã ã®éçºï¼ç¹ã«ãããã°ï¼ã«ããã¦ã¯ããã°ã使ããªãã¨è¦å´ãã¾ãããã ãããã°ãåãè¾¼ãã¨ãæ§è½ã«å½±é¿ãåã¼ãã¾ããã¾ãããã°ã¬ãã«ãæå¶ããå®éã«ã¯ãã°åºåããªãã£ãã¨ãã¦ãããã°ã¬ãã«ã®å¤å®å¦çãåããã¨ã§ãå¤å°ã®å½±é¿ã¯ããã¾ãã æè¿ã®ãã°åºåã©ã¤ãã©ãªã¯ã¹ã¬ããã»ã¼ãã«ä½ããã¦ãã¾ãããããã¯å é¨ã§æä»åºéãæã¤ãã¨ã«ãªãã®ã§ã並åå¦çã«ããã¦ã¯æä»ã«ããæ§è½ã¸ã®å½±é¿ã¯ç¡è¦ã§ãã¾ããã ããã§ãåä¸ããã»ã¹å ã§ãã«ãã¹ã¬ããã«ãã並è¡å®è¡ããããã°ã©ã ãä½æã»å®è¡ããè¤æ°ã¹ã¬ãããããã°ãåºåããã¨ãå®è¡æ§è½ã«ã©ãã ãå½±é¿ãåã¼ã
File lockFile = new File("file.lock"); int retryCount = 30; // timeout = 3sec while (! lockFile.createNewFile()) { if ((retryCount--) == 0) { throw new LockFailedException("give up!"); } Thread.sleep(100); } try { // ãã¡ã¤ã«ããã¯ã§ä¿è·ãããå¦ç ... } finally { lockFile.delete(); } ãã¸ãã¯ãã³ãã¼ã使ã£ã¦ãããå¯ä½ç¨ã®ããå¼ãæ¡ä»¶å¼ã«ä½¿ã£ã¦ãããã¨ã æ°ã«ãªãã¨ããã¯ããããããããç¥ãã¾ãããããã®ã³ã¼ãã®ä¸çªã®åé¡ã¯ "File.createNewFile() ã«é ¼ã£ãããã¯æ©æ§ã«ãªã£ã¦ãã" ãã¨ã§ããã©ããããã¨ãç°¡åã«èª¬æãã¦
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}