老师,视频里说死锁原因是同步代码块里面套了同步代码块,且持有2个以上的对象。那么同步方法怎样会造成死锁呢?
为啥我的每次运行结果都一模一样???
public class haunchongThread { public static void main(String[] args) { Zaocarcahng zaocar = new Zaocarcahng(); Thread scz = new Thread(new scz(zaocar)); Thread xfz = new Thread(new xfz(zaocar)); scz.start(); xfz.start(); } } //缓冲区 class Zaocarcahng { ArrayList c = new ArrayList<>(10); //存车 synchronized public void scc(Ccar ccar, String s){ while (c.size()>=10){//如果到10了就满了,休息 try { this.wait();//线程休息 } catch (InterruptedException e) { throw new RuntimeException(e); } }//到这里线程还在休息,无法执行下面的唤醒,所以没有冲突 this.notify();//唤醒 c.add(ccar); System.out.println(s+"生产了"+ccar.toString()); } //取车 synchronized public Ccar xsc(int ccarid){ if (c.size()<=0){//车不够了,等着休息 try { this.wait();//线程休息 } catch (InterruptedException e) { throw new RuntimeException(e); } }//到这里线程还在休息,无法执行下面的唤醒,所以没有冲突 this.notify();//唤醒 return (Ccar) c.remove(ccarid); } } //产物 class Ccar { private int id ; public Ccar() { } public Ccar(int id) { this.id = id; } @Override public String toString() { return "Ccar{" + "id=" + id + '}'; } public int getId() { return id; } public void setId(int id) { this.id = id; } } //生产者 class scz implements Runnable{ Zaocarcahng zcc; public scz(Zaocarcahng zcc) { this.zcc = zcc; } @Override public void run() { //生产 for (int i = 0; i < 20; i++) { zcc.scc(new Ccar(i),"生产者----"); } } } //消费者 class xfz implements Runnable{ Zaocarcahng zcc; public xfz(Zaocarcahng zcc) { this.zcc = zcc; } @Override public void run() { for (int i = 0; i < 20; i++) { Ccar xsc = zcc.xsc(0);//只取第1个 System.out.println("消费:"+xsc.toString()); } } }
package com.bjsxt.file; import java.io.File; import java.io.IOException; public class TestFile { //使用File类操作文件 public static void main(String[] args) throws IOException { //创建File类的对象 //File f1 = new File("\\Users\\wanglx\\Desktop\\测试图片\\140F1132T93X.txt");//绝对路径 File f2 = new File ( "/Users/wanglx/Desktop/测试图片/140F1132T93X.txt" ); File f3 = new File ( "140F1132T93X.txt" );//相对路径 File f4 = new File ("/Users/wanglx/Desktop/测试图片");//目录 File f5 = new File ( f4,"140F1132T93X.txt" );//目录下的某个文件 File f6 = new File ( "Desktop"+File.separator+"140F1132T93X.txt" );//获取系统相关的路径分隔符separator /**File操作文件相关的方法*/ System.out.println (f2.createNewFile ()); // System.out.println (f2.delete ());//直接从磁盘上删除 System.out.println (f2.exists ());//不存在返回false System.out.println ("绝对路径:"+f3.getAbsolutePath ()); System.out.println ("相对路径:"+f3.getPath ()); System.out.println ("获取文件名:"+f3.getName ()); System.out.println (f3.toString ());//相对路径 System.out.println ("f3是否是文件:"+f3.isFile ()); System.out.println ("是否是文件:"+f4.isFile ()); } }
System.out.println ("f3是否是文件:"+f3.isFile ());
返回结果:false
为什么呢
可以帮我讲讲::的作用吗,有点忘了,什么时候用如何使用
老师,getDeclaredMethod(String methodName, Class …type) 和getMethod(String methodName, Class type)的区别是什么,怎么感觉前面的用的多
老师,这边如果链表中只有一个元素时,是不是会报空指针异常?
老师,我不明白为什么类名后面要加<E>,什么意思?
老师你好,我根据视频讲的操作,但是没办法进行断点调试
public class AutoBaoZhaung { private static int value; private static AutoBaoZhaung[] shu; static int LOW = -128; static int HIGH = 127; { shu = new AutoBaoZhaung[HIGH-LOW+1]; for(int i = LOW ; i < HIGH ; i++){ shu[i-LOW] = new AutoBaoZhaung(i); } System.out.println(Arrays.toString(shu)); } @Override public String toString() { return value+""; } private static AutoBaoZhaung valueOf(int k){ if(k<HIGH&&k>LOW){ return shu[k-LOW]; } return new AutoBaoZhaung(k); } public AutoBaoZhaung(int value){ this.value = value; } private int intValue(){ return value; } public static void main(String[] args) { AutoBaoZhaung a = AutoBaoZhaung.valueOf(100); AutoBaoZhaung a1 = AutoBaoZhaung.valueOf(100); AutoBaoZhaung a2= AutoBaoZhaung.valueOf(1000); AutoBaoZhaung a3 = AutoBaoZhaung.valueOf(1000); System.out.println(a==a1); System.out.println(a2==a3); System.out.println(a.equals(a1)); System.out.println(a2.equals(a3)); } }
老师,这里为什么会报空指针异常
Iterator<String> iterator2 = list.iterator()(iterator2iterator2.hasNext()){ String val2 = iterator2.next()System..println(val2)}
为什么迭代器要在for循环内定义,这样为什么会报错呢
老师,图一红色方框的内容不是端口吗,然后HTTP服务器默认的端口为80,为什么填写HTTPS默认的端口号443也能获取到百度的服务器地址以及服务器的名称啊?
一、相关代码
if (paraString.equals("")) { return; }
二、问题描述
描述前后关系:视频23分15秒处。定义String类型的paraString用于存储请求参数。 仅当html文件的method为“get”时,将paraString赋值在urlArray[1]的部分。
问题1:当paraString为空时,为什么要return;意义何在。
问题2:
public void A() {
sout(“你好”);
return;
}
我测试如果调用A()方法,“你好”的打印语句是执行的,那么一个无返回值的A()方法中,return;的意义何在?
我想问如果是别人写的输出数据呢?,其他人是怎么知道输出数据写的顺序
老师,Set容器为啥也可以用iterator迭代器?set容器不是哈希表结构嘛,比如第一个索引位置存了一个元素,最后一个索引位置存放了一个元素,iterator不是移动游标一个一个找嘛,但中间都没有元素,hasNext就为false,也可以继续循环?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637