Created
February 26, 2014 07:41
-
-
Save Vox1oot/9225283 to your computer and use it in GitHub Desktop.
package com.javarush.test.level17.lesson10.home04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level17.lesson10.home04; | |
/* Синхронизированные методы | |
Установить модификатор synchronized только тем методам, которым необходимо | |
*/ | |
public class Solution { | |
private double param = Math.random(); | |
private void method0() { | |
double i = method3(); | |
} | |
protected synchronized void method1(String param1) { | |
Solution solution = new Solution(); | |
solution.method0(); | |
} | |
public void method2(int param1) { | |
param1++; | |
} | |
synchronized double method3() { | |
double random = Math.random(); | |
return random + param; | |
} | |
private synchronized void method4() { | |
new StringBuilder().append(1).append(1).append(1).append(1); | |
} | |
protected void method5(String param2) { | |
new StringBuffer().append(param2).append(param2).append(param2); | |
} | |
public synchronized String method6(int param2) { | |
System.out.println("Thinking...."); | |
method7(5e-2); | |
return "Got it!"; | |
} | |
String method7(double param2) { | |
return "" + param2; | |
} | |
} |
Method1 не меняет общие ресурсы, поэтому метод не нужно синхронизировать.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Сейчас это выглядит так:
package com.javarush.task.task17.task1716;
/*
Синхронизированные методы
*/
public class Solution {
private double param = Math.random();
private StringBuilder sb = new StringBuilder();
}
Очень похоже но старая логика не подходит - хотя и есть тут много спорных моментов