/*
第9章 IO流
* OutputStream write(97/bys), write(bys,index,2);
* InputStream int len=fis.read() !=-1 len=97 int len=fis.read(bys); (char)len=a
* 捕获异常标准代码:try{}catch{}finally{}
* deleteDir(src)
* getCount(hm,file)
* 字节流小数组拷贝原理:abcde
* 字节缓冲流+字节流(主):8192数组 抛出FileNotFoundException
* 字节缓冲流底层源码:8192数组
* shift+tab(后):反向缩进
*OutputStream,InputStream:write(),read()方法
* 字节缓冲流:+FileWriter:readLine(),writeLine() 跨平台的回车换行
* FileWriter,FileReader: write,read ,flush,close,FileWriter原码 FileWriter 父类:OutputStreamWriter(其需要字节输出流)
* String n=str[i];
int num=Integer.parseInt(n);//integer能在Int和string之间进行转换
*
* String n="123";
* int num=Integer.parseInt(n);//string和int之间转换
*
*
* int[] arr=
* Arrays.sort(arr);//Arrays针对数组操作
* Arrays.toString(arr);//数组内容字符串展示
* 转换流底层:
* 转换流要带上字节流
* 空指针异常,IO异常,文件找不到异常,打异常,数字化异常,非法传参异常,不合法字符集名称:illegalCharsetName
* charset f=charset.forName("GBK");
*对象操作流:
* ObjectOutputStream: writeObject(对象) 把对象写到本地文件,对象序列化,需要Serializable接口
* Serializable接口:里面没任何抽象方法
* invalidclassException(不合法类异常) extends ObjectStreamException(对象流异常)
* 原先序列号和修改后不一样
* 数据类型不一样
* 没有无参构造
*
* properties,serializable,cloneable,Hashtable<Object,Object>
<Hashtable<> <dictionary<k,v> Object
* setProperty(),getProperty,load(),store()
* */
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
/*
第10章 线程
* run(),start()
ctrl+b,ctrl+t,ctrl+alt+l
Mycallable extends Callable 要FutureTask<String> ft
mt.setName("鲜明");??、?
案例:
桌子,吃货,厨师 更改Desk类
同步锁:卖票100->0
阻塞队列等待唤醒
ArrayBlockingQueue,4接口,2实现类
BlockingQueue:put,take方法
厨师,吃货
线程六种状态:
Thread.state?????
线程池:
Executors:newCachedThreadPool();
newFixedThreadPool(2);
类型:ExecutorService
ThreadPoolExecutor(getPoolSize())<ExecutorService(接口)<Executor
餐厅员工问题:
ThreadPoolExecutor r=new ThreadPoolExecutor(2,5,2,
TimeUnit.SECONDS,
new ArrayBlockingQueue(1),
Executors.defaultThreadFactory(),
Executors.abortPolicy());
.abortPolicy()->RehectedExecutionException 提交5,只能3+对列1, 拒绝2
.discardPolicy() 不报异常 同
.discardOldestPolicy()
.CallerRunsPolicy() 没有搞完的交给主线程:绕过线程池执行
*/
/*
* 线程安全:
* 1.同步代码快
* 2.同步方法
* 3.锁机制:死锁
* */
/*
* synchronized和CAS的区别:
* */
/*
* HashMap<k,v> , put(k,v), v=get(k) new Thread(()->{hm.put(i,i)}).start()
* HashTable:锁数组
* ConcurrentHashTable:自旋+CAS, hash表(大数组+链表+红黑树)
* */
/*
* count++; 有三步,被打乱,用原子性
* volatile关键字
* AtomicInter:
* ac.get()
* ac.getAndIncrement()
* ac.getAndSet();
* */
/* new CountDownLatch(3):等待其他的线程运行完在运行
* await()
* countDown():1.锁存器 2.递减 总线程数3-2-1,放在哪个线程里都是起到计时器的作用 3.释放自己
* */
/*
* semaphere:无无参构造,可以序列化
* new semaphere(2);一次拿两张通行证
* semaphere.acquire() .release()
* */