1、java高级语法、java集合类 、Java多线程 、java IO
接口还可以这样写
测试Lambda表达式,接口的默认方法,接口的静态方法
public class LambdDemo { public static void main(String[] args) { Foo foo = (int x ,int y) -> { System.out.println(" ++++++come in here "); return x+y; }; System.out.println(foo.sayHello(3, 4)); System.out.println(foo.mv(3, 5)); System.out.println(Foo.div(4, 5)); } }
声明资源类
class Ticket { int number = 30; private Lock lock = new ReentrantLock(); public void saleTicket() { try{ lock.lock(); if (number >0 ){ System.out.println(Thread.currentThread().getName()+"线程\t买出的票"+(number--)+"还剩下的票:"+ number); } }finally { lock.unlock(); } } }
测试多线程访问资源类
public static void main(String[] args) { Ticket ticket = new Ticket(); new Thread(()->{ for(int i=1;i<40;i++) { ticket.saleTicket(); } },"A").start(); new Thread(()->{ for(int i=1;i<40;i++) { ticket.saleTicket(); } },"B").start(); new Thread(()->{ for(int i=1;i<40;i++) { ticket.saleTicket(); } },"C").start(); }