问题:看jdk源码,看懂之后,需要亲自敲一遍吗?
老师dom4j关于Xpath获取带有指定属性的节点的语法,和Xpath上为什么一样呢?这两个有什么关系?
能讲点服务器监听知识吗?例如为啥监听端口设置成8888
老师,为什么temp要用int类型,这里不是字符输入吗,不应该是String类型吗 String temp = "";为什么不是这样
按照老师的步骤敲,加上synchronized方法后会报错java: illegal start of expression,仔细检查了下好像也没敲错,文档用的表示方式和老师敲的也不太一样,请问是为什么
class Programmer{ private String name; public Programmer(String name){ this.name = name; } public void coding() { synchronized (){ try { System.out.println(this.name + " double click Idea"); Thread.sleep(500); System.out.println(this.name+" Idea start"); Thread.sleep(500); System.out.println(this.name+" happy coding"); } catch (InterruptedException e) { e.printStackTrace(); } } } public void computer() { synchronized (){ try { System.out.println(this.name + " POWER ON"); Thread.sleep(500); System.out.println(this.name + " press on"); Thread.sleep(500); System.out.println(this.name + " system starting"); Thread.sleep(500); System.out.println(this.name + " System On"); } catch (InterruptedException e) { e.printStackTrace(); } } } } class Working1 extends Thread{ private Programmer p; public Working1(Programmer p){ this.p = p; } @Override public void run() { this.p.computer(); } } class Working2 extends Thread{ private Programmer p; public Working2(Programmer p){ this.p = p; } @Override public void run() { this.p.coding(); } } public class TestSyncThread { public static void main(String[] args) { Programmer p = new Programmer("Lee"); new Working1(p).start(); new Working2(p).start(); } }
package com.bjsxt.ls.DuoXianCheng.线程并发; /* 线程并发:生产者和消费者模型 定义一个做馒头和取馒头的类,中间有一个缓冲区。做好的馒头放入缓冲区,取馒头从缓冲区取。 假设缓冲区容量是10,那么当做了十个馒头的时候,做馒头线程就要停止(阻塞)。当缓冲区没有馒头的时候,取馒头线程就要停止(阻塞)。 但是当做馒头线程放入馒头的时候,就要用notify提醒取馒头线程,不要一直处于阻塞状态; 同样当取馒头线程拿馒头的时候,也要提醒做馒头线程要做馒头,不要一直处于阻塞状态; */ //定义馒头类 class ManTou{ private int id; public ManTou(int id) { this.id = id; } public int getId() { return id; } } //定义缓冲区,用数组来存放馒头 class resitor{ private ManTou[] arr =new ManTou[10]; //创建一个长度为10,类型为ManTou的数组 private int index; //定义索引 //定义做馒头方法 //因为做馒头和取馒头都是对同样对象进行操作,所以这两个状态是要互斥,即同步的。所以要用synchronized使得这两个状态处于同步状态 //synchronzied放在方法名上相当于将synchronized(this){}将方法体包裹起来。 public synchronized void makeMantou(ManTou manTou){ //用while做出判断,如果当数组满的时候,就要用wait方法,使得此线程进入阻塞状态,不再生产馒头了; while (this.index == this.arr.length){ try { wait(); /*wait属于Object类只能用在synchronized块中。 此方法执行之后,在本方法所在的对象锁会被阻塞, 其他需要该对象锁的线程就可以继续运行了。*/ } catch (InterruptedException e) { e.printStackTrace(); } } //notify也属于Object类 this.notify();//当放入馒头的时候,要用notify唤醒取馒头的线程,以防拿馒头线程处于阻塞状态 。 //该方法会唤醒处于等待状态队列中的一个线程 this.arr[this.index]=manTou; index++; } //定义取馒头方法 public synchronized ManTou takeMantou(){ //用while判断,当索引为0,即缓冲区没有馒头的时候,就用wait阻塞此状态,不要再去取馒头了; while (this.index==0){ try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } this.notify();//拿馒头的时候也要唤醒做馒头的线程,以防处于阻塞状态不做馒头了。 this.index--; return this.arr[this.index]; } } //创建做馒头线程 class makeThread extends Thread{ private resitor r; //定义一个类型是resitor的变量r public makeThread(resitor r){ this.r = r; } @Override public void run() { for (int i=1;i<11;i++){ System.out.println("生成第"+i+"个馒头"); ManTou manTou =new ManTou(i); this.r.push(manTou); } } } //创建取馒头线程 class takeThread extends Thread{ private resitor r; //定义一个类型是resitor的变量r public takeThread(resitor r){ this.r = r; } @Override public void run() { for (int i=1;i<11;i++){ ManTou manTou =this.r.pop(); System.out.println("拿走第"+i+"个馒头"); } } } public class ProducerThread { public static void main(String[] args) { resitor tt =new resitor(); new makeThread(tt).start(); new takeThread(tt).start(); } }
老师这是什么原因造成的?
老师,视频里整理的笔记呢 左面为啥没有文档了
听的模模糊糊的,真的是看了三四遍都不懂,锁对象中什么时候用this,什么时候用““,真的看不懂
import java.io.IOException; public class TestStopThread implements Runnable{ //生死牌 true:生;false:死 private boolean flag = true; @Override public void run() { System.out.println(Thread.currentThread().getName()+"线程开始"); int i = 0; while(this.flag){ System.out.println(Thread.currentThread().getName()+" "+i++); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println(Thread.currentThread().getName()+"线程结束"); } //控制生死牌内容的方法 public void stop(){ this.flag = false; } public static void main(String[] args) { System.out.println("主线程开始"); TestStopThread tst = new TestStopThread(); Thread t = new Thread(tst); t.start(); try{ System.in.read(); }catch (IOException e){ e.printStackTrace(); } tst.stop(); System.out.println("主线程结束"); } }
为什么“主程序开始”和“主程序结束”都不打印?
这个是栈吗?也没看到有栈的结构在这里呀?但是老师在讲课的时候一直在说栈,
而且他给我们画的不一直是树的遍历?怎么画栈的内存图?
不明白这里为什么与视频中不一样出现了很多次重复数字,list应该是可重复的但视频中并未出现。。。
老师这个是什么问题
package com.bjxst; public class MyDoublyLinkedList<E> implements MyList<E> { private Node head; private Node tail; private int size; @Override public void add(E element) { this.linkedLast(element); } private void linkedLast(E element){ //首先获取尾部节点 Node t = this.tail; //创建节点对象 Node node1 =new Node(t,null,element); node1=this.tail; if(t==null){ node1 =this.head; }else{ node1 = t.next; } this.size++; } @Override public E get(int index) { //对Index做合法性校验 this.checkIndex(index); //根据节点对象查找位置 Node<E> node = this.getNode(index); return node.item; } private void checkIndex(int index){ if(!(index>=0&&index<this.size)){ throw new IndexOutOfBoundsException("index"+index+"size"+size); } } private Node getNode(int index){ if (index<(this.size>>1)){ Node node = this.head; for (int i=0;i<index;i++){ node = node.next; } return node; }else{ Node node = this.tail; for (int i=this.size-1;i>index;i--){ node = node = node.prev; } return node; } } @Override public int size() { return this.size; } @Override public E remove(int index) { //对index进行合法性校验 this.checkIndex(index); //根据指定位置获取节点对象 Node<E> node = this.getNode(index); //获取节点对象中的元素 E item = node.item; //判断当前节点是否为头节点 if(node.prev ==null){ node.next=this.head; }else{ node.prev.next = node.next; } //判断当前节点是否为尾结点 if(node.next==null){ node.prev = this.tail; }else{ node.next.prev = node.prev; } node.next =null; node.prev= null; node.item =null; this.size--; return item; } //创建节点内部类 class Node<E>{ E item; Node<E> prev; Node<E> next; Node(Node<E> prev,Node<E> next,E item){ this.prev = prev; this.next=next; this.item = item; } } public void addFirst(E element){ this.linkFirst(element); } private void linkFirst(E element){ //获取头结点对象 Node head = this.head; Node node1 = new Node(null,head,element); //将新节点定为头节点 node1 =this.head; if(head==null){ node1 = this.tail; }else{ node1=head.prev; } this.size++; } public void addLast(E element){ this.linkedLast(element); } public static void main(String[] args) { MyList<String> myList = new MyDoublyLinkedList<>(); myList.add("a"); myList.add("b"); myList.add("at"); myList.add("e"); myList.add("e"); System.out.println(myList.remove(3)); } }
为什莫资料中WebDom4j .java中运行会出现
老师,我的代码和视频中的一模一样,但是出现的是这样的
请问这是怎么回事?我的文件是保存在E盘里面
public static void main(String[] args) throws InterruptedException, ExecutionException { // 如何创建一个线程池 ExecutorService pool1 = Executors.newCachedThreadPool(); /**使用线程池执行大量的Callable任务*/ for(int i=0;i<20;i++){ //使用匿名内部类 //创建任务 Callable<Integer> task=new Callable<Integer>() { @Override public Integer call() throws Exception { Thread.sleep(2000); return (int)(Math.random()*10)+1; } }; //任务结束 //将任务交能线程池 Future f=pool1.submit(task); System.out.println(f.get()); } pool1.shutdown(); }
老师请问,Callable是一个接口。它凭什么就能被new出来,居然还能被执行。
我查过,没有同名类
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637