packagecom.ysf;publicclassTst02AtomicSync{privatestaticint count =0;publicstaticvoidincrement(){synchronized(Tst02AtomicSync.class){count++;}try{Thread.sleep(10L);}catch(InterruptedException e){e.printStackTrace();}}publicstaticvoidmain(String[] args)throwsInterruptedException{Thread t1 =newThread(()->{for(int i =0; i <100; i++){increment();}},"plus-1");Thread t2 =newThread(()->{for(int i =0; i <100; i++){increment();}},"plus-2");t1.start();t2.start();t1.join();t2.join();System.out.println(count);}}
我们可以使用bindService来跨进程通信,其使用方法如下
Intent intent new Intent("xxx");
intent.setPackage("xxx");
boolean result bindService(intent,new ServiceConn(),BIND_AUTO_CREATE);private class ServiceConn implements Servi…
背景
在做一道easy题,二叉树的中序遍历,我提交的代码如下
from typing import (Optional,List
)# Definition for a binary tree node.
class TreeNode:def __init__(self, val0, leftNone, rightNone):self.val valself.left leftself.right right…