public static void main(String[] args) { ThreadTest9 a = new ThreadTest9("1", "", "1"); ThreadTest9 b = new ThreadTest9("1", "", "2"); ThreadTest9 c = new ThreadTest9("3", "", "3"); ThreadTest9 d = new ThreadTest9("4", "", "4"); System.out.println("begin:" + (System.currentTimeMillis() / 1000)); a.start(); b.start(); c.start(); d.start(); }
public void run() { testDo.doSome(key, value); } }
class TestDo { private TestDo() {} private static TestDo _instance = new TestDo(); private CopyOnWriteArrayList keys = new CopyOnWriteArrayList<>();
public static TestDo getInstance() { return _instance; }
public void doSome(String key, String value) { Object o = key; if (!keys.contains(o)) { keys.add(o); } else { for (String k : keys) { if (k.equals(o)) { o = k; break; } } } synchronized (o) { try { Thread.sleep(1000); System.out.println(key + ":" + value + ":" + (System.currentTimeMillis() / 1000)); } catch (InterruptedException e) { e.printStackTrace(); } } } } ```
Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ...
[详细]