//关于查看电脑CPU的核数
public class CpuNum {
public static void main(String[] args) {
Runtime r = Runtime.getRuntime();
int c = r.availableProcessors();
System.out.println(c);
}
}
//线程的使用:
//首先需要继承Thread类,重写run方法
//然后需要实现Runnable接口,重写run方法
package cpu;
//当一个类继承了Thread类 该类就可以当做线程使用
//重写run方法 写上自己的业务代码
//run Thread 类 实现了 Runnable 接口的run方法
//主线程和子线程是交替进行的
public class Thread01 {
public static void main(String[] args) {
Cat cat = new Cat();
cat.start();//启动线程
// cat.run();//run方法并不会启动线程
//run方法只是一个普通的方法
//真正实现多线程的效果是 start0()方法 而不是 run()方法
}
}
class Cat extends Thread{
int times = 0;
@Override
public void run() {
// super.run();
while(true) {
System.out.println("wswswswwww"+(++times)+"线程名字+"+Thread.currentThread().getName());
//休息1秒钟 ctrl + alt + t
try {
Thread.sleep(1000);//1秒钟
} catch (Exception e) {
e.printStackTrace();
}
if(times == 8)
{
break;
}
}
}
}
package homework;
//并发修改异常
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class homework3 {
public static void main(String[] args) {
//创建集合对象
List list = new ArrayList();
//添加元素
list.add("1");
list.add("2");
list.add("3");
ListIterator lit = list.listIterator();
while(lit.hasNext())
{
String s = lit.next();
if(s.equals("1"))
{
lit.add("111");
}
}
System.out.println(list);
// while(lit.hasNext())
// //正向遍历
// {
// String s = lit.next();
// System.out.println(s);
// }
//--------------------------------------------------
// while(lit.hasPrevious())
// //逆向遍历
// {
// String s = lit.previous();
// System.out.println(s);
// }
// ListIterator lit = list.listIterator();
// while(lit.hasNext())
// {
// String s = lit.next();
// System.out.println(s);
// }
// //
// Iterator it = list.iterator();
// while(it.hasNext())
// {
// String s = it.next();
// System.out.println(s);
// if(s.equals("2"))
// {
// list.add("11");
// }
// }
// for(int i = 0;i