201871010111-刘佳华《面向对象程序设计(java)》第十六周学习总结
学号-姓名《面向对象程序设计(java)》第十六周学习总结
实验十四 应用程序归档与线程初步
实验时间 2019-12-12
第一部分:理论知识总结
1、程序与进程的概念
‐程序是一段静态的代码,它是应用程序执行的蓝本。
‐进程是程序的一次动态执行,它对应了从代码加载、执行至执行完毕的一个完整过程。
‐操作系统为每个进程分配一段独立的内存空间和系统资源,包括:代码数据以及堆栈等资源。每 一个进程的内部数据和状态都是完全独立的。
‐多任务操作系统中,进程切换对CPU资源消耗较大。
2、多线程的概念
‐多线程是进程执行过程中产生的多条执行线索。
‐线程是比进程执行更小的单位。
‐线程不能独立存在,必须存在于进程中,同一进程的各线程间共享进程空间的数据。
‐每个线程有它自身的产生、存在和消亡的过程, 是一个动态的概念。
‐多线程意味着一个程序的多行语句可以看上去几 乎在同一时间内同时运行。
‐线程创建、销毁和切换的负荷远小于进程,又称为轻量级进程(lightweight process)。
3、Java实现多线程有两种途径:
‐创建Thread类的子类
‐在程序中定义实现Runnable接口的类
4、用Thread类子类创建线程
首先需从Thread类派生出一个子类,在该子类中重写run()方法。
class hand extends Thread
{
public void run()
{……}
}
5、用Thread类的子类创建多线程的关键性操作
–定义Thread类的子类并实现用户线程操作,即 run()方法的实现。
–在适当的时候启动线程。
由于Java只支持单重继承,用这种方法定义的类不可再继承其他父类。
6、用Runnable()接口实现线程
- 首先设计一个实现Runnable接口的类;
- 然后在类中根据需要重写run方法;
- 再创建该类对象,以此对象为参数建立Thread 类的对象;
- 调用Thread类对象的start方法启动线程,将 CPU执行权转交到run方法。
7、线程的终止
-当线程的run方法执行方法体中最后一条语句后,或者出现了在run方法中没有捕获的异常时,线程将终止,让出CPU使用权。
- 调用interrupt()方法也可终止线程。
void interrupt()
– 向一个线程发送一个中断请求,同时把这个线程的“interrupted”状态置为true。
– 若该线程处于 blocked 状态 ,会抛出 InterruptedException。
8、测试线程是否被中断的方法
Java提供了几个用于测试线程是否被中断的方法。
-static boolean interrupted()
– 检测当前线程是否已被中断 ,并重置状态 “interrupted”值为false。
-boolean isInterrupted()
– 检测当前线程是否已被中断 ,不改变状态 “interrupted”值 。
9、线程的状态
-利用各线程的状态变换,可以控制各个线程轮流使用CPU,体现多线程的并行性特征。
-线程有如下7种状态:
➢ New (新建)
➢ Runnable (可运行)
➢ Running(运行)
➢ Blocked (被阻塞)
➢ Waiting (等待)
➢ Timed waiting (计时等待)
➢ Terminated (被终止)
10、新创建线程
-new(新建)
线程对象刚刚创建,还没有启动,此时线程还处于不可运行状态。例如: Thread thread=new Thread(r); 此时线程thread处于新建状态,有了相应的内存空间以及其它资源。
11、可运行线程
- runnable(可运行状态)
➢ 此时线程已经启动,处于线程的run()方法之中。
➢ 此时的线程可能运行,也可能不运行,只要 CPU一空闲,马上就会运行。
➢ 调用线程的start()方法可使线程处于“可运行”状态。例如: thread.start();
12、被阻塞线程和等待线程
- blocked (被阻塞)
➢ 一个正在执行的线程因特殊原因,被暂停执行, 进入阻塞状态。
➢ 阻塞时线程不能进入队列排队,必须等到引起阻塞的原因消除,才可重新进入排队队列。
➢ 引起阻塞的原因很多,不同原因要用不同的方法解除。
-sleep(),wait()是两个常用引起线程阻塞的方法。
13、线程阻塞的三种情况
- 等待阻塞 -- 通过调用线程的wait()方法,让线程等待某工作的完成。
- 同步阻塞 -- 线程在获取synchronized同步锁失败(因为锁被其它线程所占用),它会进入同步阻塞状态。
-其他阻塞 -- 通过调用线程的sleep()或join() 或发出了I/O请求时,线程会进入到阻塞状态。当 sleep()状态超时、join()等待线程终止或者超 时、或者I/O处理完毕时,线程重新转入就绪状态。
14、被终止的线程
Terminated (被终止) 线程被终止的原因有二:
➢ 一是run()方法中最后一个语句执行完毕而自然死亡。
➢ 二是因为一个没有捕获的异常终止了run方法而意外死亡。
➢ 可以调用线程的 stop 方 法 杀 死 一 个 线 程(thread.stop();),但是,stop方法已过时, 不要在自己的代码中调用它。
15、多线程调度
-Java 的线程调度采用优先级策略:
➢ 优先级高的先执行,优先级低的后执行;
➢ 多线程系统会自动为每个线程分配一个优先级,缺省时,继承其父类的优先级;
➢ 任务紧急的线程,其优先级较高;
➢ 同优先级的线程按“先进先出”的队列原则;
第二部分:实验部分
1、实验目的与要求
(1) 掌握Java应用程序的打包操作;
(2) 掌握线程概念;
(3) 掌握线程创建的两种技术。
2、实验内容和步骤
实验1: 导入第13章示例程序,测试程序并进行代码注释。
测试程序1
l 在elipse IDE中调试运行教材585页程序13-1,结合程序运行结果理解程序;
l 将所生成的JAR文件移到另外一个不同的目录中,再运行该归档文件,以便确认程序是从JAR文件中,而不是从当前目录中读取的资源。
l 掌握创建JAR文件的方法;
- package resource;
- import java.awt.*;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import javax.swing.*;
- /**
- * @version 1.41 2015-06-12
- * @author Cay Horstmann
- */
- public class ResourceTest
- {
- public static void main(String[] args)
- {
- EventQueue.invokeLater(() -> {
- JFrame frame = new ResourceTestFrame();
- frame.setTitle("ResourceTest");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- });
- }
- }
- /**
- * A frame that loads image and text resources.
- */
- class ResourceTestFrame extends JFrame
- {
- private static final int DEFAULT_WIDTH = 300;
- private static final int DEFAULT_HEIGHT = 300;
- public ResourceTestFrame()
- {
- setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- URL aboutURL = getClass().getResource("about.gif"); //ip地址的路径地址,资源加载代码
- Image img = new ImageIcon(aboutURL).getImage();
- setIconImage(img);
- JTextArea textArea = new JTextArea();
- InputStream stream = getClass().getResourceAsStream("about.txt");
- try (Scanner in = new Scanner(stream, "UTF-8"))
- {
- while (in.hasNext())
- textArea.append(in.nextLine() + "\n");//显示
- }
- add(textArea);
- }
- }
ResourceTest
运行截图:
归档及之后运行截图:
双击打开:
测试程序2:
l 在elipse IDE中调试运行ThreadTest,结合程序运行结果理解程序;
l 掌握线程概念;
l 掌握用Thread的扩展类实现线程的方法;
l 利用Runnable接口改造程序,掌握用Runnable接口创建线程的方法。
class Lefthand extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println("You are Students!"); try{ sleep(500); } catch(InterruptedException e) { System.out.println("Lefthand error.");} } } } class Righthand extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println("I am a Teacher!"); try{ sleep(300); } catch(InterruptedException e) { System.out.println("Righthand error.");} } } } public class ThreadTest { static Lefthand left; static Righthand right; public static void main(String[] args) { left=new Lefthand(); right=new Righthand(); left.start(); right.start(); } } |
源代码导入:
- package Thread;
- class Lefthand extends Thread {
- public void run()
- {
- for(int i=0;i<=5;i++)
- { System.out.println("You are Students!");
- try{ sleep(500); } //sleep(500);为定时等待500ms,sleep配合使用try-catch字句
- catch(InterruptedException e)
- { System.out.println("Lefthand error.");}
- }
- }
- }
- class Righthand extends Thread {
- public void run()
- {
- for(int i=0;i<=5;i++)
- { System.out.println("I am a Teacher!");
- try{ sleep(300); }
- catch(InterruptedException e)
- { System.out.println("Righthand error.");}
- }
- }
- }
- public class ThreadTest
- {
- static Lefthand left;
- static Righthand right;
- public static void main(String[] args)
- { left=new Lefthand();//创建对象
- right=new Righthand();
- left.start();//开始进程
- right.start();
- }
- }
ThreadTest
修改后代码:
- package Thread;
- class Lefthands implements Runnable{
- public void run() {
- for(int i=0;i<=5;i++)
- { System.out.println("You are Students!");
- try{ Thread.sleep(500); }
- catch(InterruptedException e)
- { System.out.println("Lefthand error.");}
- }
- }
- }
- class Righthands implements Runnable{
- public void run() {
- for(int i=0;i<=5;i++)
- { System.out.println("I am a Teacher!");
- try{ Thread.sleep(300); }
- catch(InterruptedException e)
- { System.out.println("Righthand error.");}
- }
- }
- }
- public class TheadTest01 {
- public static void main(String args[]) {
- Lefthands L=new Lefthands();
- Righthands R=new Righthands();
- new Thread(L).start();
- new Thread(R).start();
- }
- }
TheadTest01
运行截图:(与源代码运行一致)
测试程序3:
l 在Elipse环境下调试教材625页程序14-1、14-2 、14-3,结合程序运行结果理解程序;
l 在Elipse环境下调试教材631页程序14-4,结合程序运行结果理解程序;
l 对比两个程序,理解线程的概念和用途;
l 掌握线程创建的两种技术。
p625 14.1-14.3程序:
- package bounce;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- /**
- * Shows an animated bouncing ball.
- * @version 1.34 2015-06-21
- * @author Cay Horstmann
- */
- public class Bounce
- {
- public static void main(String[] args)
- {
- EventQueue.invokeLater(() -> {
- JFrame frame = new BounceFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- });
- }
- }
- /**
- * The frame with ball component and buttons.
- */
- class BounceFrame extends JFrame
- {
- private BallComponent comp;
- public static final int STEPS = 1000;
- public static final int DELAY = 3;
- /**
- * Constructs the frame with the component for showing the bouncing ball and
- * Start and Close buttons
- */
- public BounceFrame()//构造包含用于显示弹跳球和启动和关闭按钮
- {
- setTitle("Bounce");
- comp = new BallComponent();
- add(comp, BorderLayout.CENTER);
- JPanel buttonPanel = new JPanel();
- addButton(buttonPanel, "Start", event -> addBall());
- addButton(buttonPanel, "Close", event -> System.exit(0));
- add(buttonPanel, BorderLayout.SOUTH);
- pack();
- }
- /**
- * Adds a button to a container.
- * @param c the container
- * @param title the button title
- * @param listener the action listener for the button
- */
- public void addButton(Container c, String title, ActionListener listener)//Adds a button to a container.
- {
- JButton button = new JButton(title);
- c.add(button);
- button.addActionListener(listener);
- }
- /**
- * Adds a bouncing ball to the panel and makes it bounce 1,000 times.
- */
- public void addBall()//在面板中添加一个弹跳球,使其弹跳1000次。
- {
- try
- {
- Ball ball = new Ball();
- comp.add(ball);
- for (int i = 1; i <= STEPS; i++)
- {
- ball.move(comp.getBounds());
- comp.paint(comp.getGraphics());
- Thread.sleep(DELAY);
- }
- }
- catch (InterruptedException e)
- {
- }
- }
- }
Bounce
- package bounce;
- import java.awt.*;
- import java.util.*;
- import javax.swing.*;
- /**
- * The component that draws the balls.
- * @version 1.34 2012-01-26
- * @author Cay Horstmann
- */
- public class BallComponent extends JPanel
- {
- private static final int DEFAULT_WIDTH = 450;
- private static final int DEFAULT_HEIGHT = 350;
- private java.util.List<Ball> balls = new ArrayList<>();
- /**
- * Add a ball to the component.
- * @param b the ball to add
- */
- public void add(Ball b)//将球添加到组件。
- {
- balls.add(b);
- }
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g); // 删除背景
- Graphics2D g2 = (Graphics2D) g;
- for (Ball b : balls)
- {
- g2.fill(b.getShape());
- }
- }
- public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
- }
BallComponent
- package bounce;
- import java.awt.geom.*;
- /**
- * A ball that moves and bounces off the edges of a rectangle
- * @version 1.33 2007-05-17
- * @author Cay Horstmann
- */
- public class Ball
- {
- private static final int XSIZE = 15;
- private static final int YSIZE = 15;
- private double x = 0;
- private double y = 0;
- private double dx = 1;
- private double dy = 1;
- /**
- * Moves the ball to the next position, reversing direction if it hits one of the edges
- */
- public void move(Rectangle2D bounds)//将球移动到下一个位置,如果碰到其中一个边,则反转方向
- {
- x += dx; //x y方向上依次加位移增量
- y += dy;
- if (x < bounds.getMinX())
- {
- x = bounds.getMinX();
- dx = -dx;
- }
- if (x + XSIZE >= bounds.getMaxX())
- {
- x = bounds.getMaxX() - XSIZE;
- dx = -dx;
- }
- if (y < bounds.getMinY())
- {
- y = bounds.getMinY();
- dy = -dy;
- }
- if (y + YSIZE >= bounds.getMaxY())
- {
- y = bounds.getMaxY() - YSIZE;
- dy = -dy;
- }
- }
- /**
- * Gets the shape of the ball at its current position.
- */
- public Ellipse2D getShape() //获取球在其当前位置的形状。
- {
- return new Ellipse2D.Double(x, y, XSIZE, YSIZE);
- }
- }
Ball
运行截图:
14.4示例程序:
- package bounceThread;
- import java.awt.geom.*;
- /**
- A ball that moves and bounces off the edges of a
- rectangle
- * @version 1.33 2007-05-17
- * @author Cay Horstmann
- */
- public class Ball
- {
- private static final int XSIZE = 15;
- private static final int YSIZE = 15;
- private double x = 0;
- private double y = 0;
- private double dx = 1;
- private double dy = 1;
- /**
- Moves the ball to the next position, reversing direction
- if it hits one of the edges
- */
- public void move(Rectangle2D bounds)//将球移动到下一个位置,如果碰到其中一个边,则反转方向
- { //x y方向上依次加位移增量
- x += dx;
- y += dy;
- if (x < bounds.getMinX())
- {
- x = bounds.getMinX();
- dx = -dx;
- }
- if (x + XSIZE >= bounds.getMaxX())
- {
- x = bounds.getMaxX() - XSIZE;
- dx = -dx;
- }
- if (y < bounds.getMinY())
- {
- y = bounds.getMinY();
- dy = -dy;
- }
- if (y + YSIZE >= bounds.getMaxY())
- {
- y = bounds.getMaxY() - YSIZE;
- dy = -dy;
- }
- }
- /**
- Gets the shape of the ball at its current position.
- */
- public Ellipse2D getShape()
- {
- return new Ellipse2D.Double(x, y, XSIZE, YSIZE);
- }
- }
Ball
- package bounceThread;
- import java.awt.*;
- import java.util.*;
- import javax.swing.*;
- /**
- * The component that draws the balls.
- * @version 1.34 2012-01-26
- * @author Cay Horstmann
- */
- public class BallComponent extends JComponent
- {
- private static final int DEFAULT_WIDTH = 450;
- private static final int DEFAULT_HEIGHT = 350;
- private java.util.List<Ball> balls = new ArrayList<>();
- /**
- * Add a ball to the panel.
- * @param b the ball to add
- */
- public void add(Ball b)//将球添加到组件。
- {
- balls.add(b);
- }
- public void paintComponent(Graphics g)
- {
- Graphics2D g2 = (Graphics2D) g;
- for (Ball b : balls)
- {
- g2.fill(b.getShape());
- }
- }
- public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
- }
BallComponent
- package bounceThread;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- /**
- * Shows animated bouncing balls.
- * @version 1.34 2015-06-21
- * @author Cay Horstmann
- */
- public class BounceThread
- {
- public static void main(String[] args)
- {
- EventQueue.invokeLater(() -> {
- JFrame frame = new BounceFrame();
- frame.setTitle("BounceThread");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- });
- }
- }
- /**
- * The frame with panel and buttons.
- */
- class BounceFrame extends JFrame
- {
- private BallComponent comp;
- public static final int STEPS = 1000;
- public static final int DELAY = 5;
- /**
- * Constructs the frame with the component for showing the bouncing ball and
- * Start and Close buttons
- */
- public BounceFrame()
- {
- comp = new BallComponent();
- add(comp, BorderLayout.CENTER);
- JPanel buttonPanel = new JPanel();
- addButton(buttonPanel, "Start", event -> addBall());
- addButton(buttonPanel, "Close", event -> System.exit(0));
- add(buttonPanel, BorderLayout.SOUTH);
- pack();
- }
- /**
- * Adds a button to a container.
- * @param c the container
- * @param title the button title
- * @param listener the action listener for the button
- */
- public void addButton(Container c, String title, ActionListener listener)
- {
- JButton button = new JButton(title);
- c.add(button);
- button.addActionListener(listener);
- }
- /**
- * Adds a bouncing ball to the canvas and starts a thread to make it bounce
- */
- public void addBall()//在画布上添加一个弹跳球并开始一条线程使其弹跳
- {
- Ball ball = new Ball();
- comp.add(ball);
- Runnable r = () -> {
- try
- {
- for (int i = 1; i <= STEPS; i++)
- {
- ball.move(comp.getBounds());
- comp.repaint();//重新绘制小球
- Thread.sleep(DELAY);
- }
- }
- catch (InterruptedException e)
- {
- }
- };
- Thread t = new Thread(r);
- t.start();//利用线程开始像面板上添加小球
- }
- }
BounceThread
运行截图:
实验2:结对编程练习:采用GUI界面设计以下程序,并创建程序归档文件。
设计一个100以内整数小学生四则运算练习程序,由计算机随机产生10道加减乘除练习题,学生输入答案,由程序检查答案是否正确,每道题正确计10分,错误不计分,10道题测试结束后给出测试总分;
将程序中测试练习题及学生答题结果输出到文件,文件名为test.txt。
1)、整体编程思路:设计简单的布局情况实现对于小学生随机练习的功能实现,用到了简单的GUI页面布局管理,以及文件的读写操作。
实验简单流程图:
结对过程图片:
2) 符合编程规范的程序代码;
代码如下:
- package TeamWork05;
- import java.awt.*;
- import java.awt.Image;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- public class CalculaterTest {
- public static void main(String args[]) {
- EventQueue.invokeLater(()->{
- JFrame frame =new CalculaterFrame();
- frame.setTitle("小学生练习题集 ");
- Image img=new ImageIcon("0.jpg").getImage();
- frame.setIconImage(img);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- });
- }
- }
CalculaterTest
- package TeamWork05;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import javax.swing.*;
- public class CalculaterFrame extends JFrame {
- private static final int WIDTH=500;
- private static final int HEIGHT=500;
- int i = 0, i1 = 0, k = 0, sum = 0;
- private PrintWriter out = null;
- private String[] c1 = new String[10];
- private String[] c2 = new String[10];
- public CalculaterFrame (){
- setSize(WIDTH, HEIGHT);
- setLayout(new GridLayout(3, 1));
- JPanel panelf =new JPanel();
- JTextField jt1 = new JTextField(15);
- jt1.setEditable(false);
- JTextField jt2 = new JTextField(8);
- JLabel jt3 = new JLabel();
- jt3.setText("■");
- panelf.add(new JLabel("题目:"));
- panelf.add(jt1);
- panelf.add(new JLabel("答题区:"));
- panelf.add(jt2);
- panelf.add(new JLabel("判断区:"));
- panelf.add(jt3);
- JPanel panel1 = new JPanel();
- JButton button1 = new JButton("开始");
- JButton button2 = new JButton("生成文件");
- JButton button3=new JButton("点击查看作答情况");
- panel1.add(button1);
- panel1.add(button2);
- panel1.add(button3);
- JTextArea Jt=new JTextArea(10,10);
- JScrollPane l=new JScrollPane(Jt);
- Jt.setEditable(false);
- this.add(panelf);
- this.add(panel1);
- this.add(l);
- button1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- button1.setText("下一题");
- jt2.setText(null);
- jt3.setText(null);
- if (i < 10) {
- int a = (int) (Math.random() * 100);
- int b = (int) (Math.random() * 100);
- int m = (int) Math.round(Math.random() * 3);
- switch (m) {
- case 0:
- while (b == 0 || a % b != 0) {
- b = (int) Math.round(Math.random() * 100);
- a = (int) Math.round(Math.random() * 100);
- }
- jt1.setText("第"+(i+1)+"题:" + a + "/" + b + "=");
- c1[i] = jt1.getText();
- k = a / b;
- i++;
- break;
- case 1:
- jt1.setText("第"+(i+1)+"题:" + a + "*" + b + "=");
- c1[i] = jt1.getText();
- k = a * b;
- i++;
- break;
- case 2:
- jt1.setText("第"+(i+1)+"题:" + a + "+" + b + "=");
- c1[i] = jt1.getText();
- k = a + b;
- i++;
- break;
- case 3:
- while (a < b) {
- int x = a;
- a = b;
- b = x;
- }
- jt1.setText("第"+(i+1)+"题:" + a + "-" + b + "=");
- c1[i] = jt1.getText();
- k = a - b;
- i++;
- break;
- }
- }
- }
- });
- jt2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (i < 11) {
- int find = Integer.parseInt(jt2.getText());
- String d = jt2.getText().toString().trim();
- if (jt2.getText() != "") {
- if (find == k) {
- sum += 10;
- jt3.setText("✔");
- jt3.setForeground(Color.green);
- } else
- { jt3.setText("✘");
- jt3.setForeground(Color.red);}
- }
- c2[i1] = d;
- i1++;
- }
- }
- });
- button2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- out = new PrintWriter("text.txt");
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- for (int counter = 0; counter < 10; counter++) {
- out.println(c1[counter] + c2[counter]);
- }
- out.println("成绩为" + sum);
- out.close();
- }
- });
- button3.addActionListener(e->{
- try {
- File file = new File("D:\\JAVA2\\WEEK16\\text.txt");
- FileInputStream fis = new FileInputStream(file);
- BufferedReader in = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
- String s = null;
- while((s=in.readLine())!=null)
- {
- Jt.append(s+"\n");
- }
- in.close();
- }catch (FileNotFoundException e1) {
- System.out.println("文件未找到!");
- e1.printStackTrace();
- } catch (IOException e1) {
- System.out.println("文件打开错误!");
- e1.printStackTrace();
- }
- });
- }
- }
CalculaterFrame
程序运行截图:
单击开始开始答题;作答过程正误判断;
下面对文件实施归档:
在归档完成后桌面显示1.jar文件
打开后为可以运行的jar程序:
第三部分:实验心得体会
多线程是进程执行过程中产生的多条执行线索。线程是比进程执行更小的单位。线程不能独立存在,必须存在于进程中,同一进程的各线程间共享进程空间的数据。每个线程有它自身的产生、存在和消亡的过程,是一个动态的概念。多线程意味着一个程序的多行语句可以看上去几乎在同一时间内同时运行。线程创建、销毁和切换的负荷远小于进程,又称为轻量级进程。
本周了解到了线程以及线程两种创建方法,再次做一个比较:实现Runnable接口的优势:符合OO设计的思想;便于用extends继承其它类。采用继承Thread类方法的优点:代码简单。通过本周的结对编程,发现之前学的知识遗忘比较快,在文件读取这一块还是以往较严重,在之后还得看一下。
201871010111-刘佳华《面向对象程序设计(java)》第十六周学习总结的更多相关文章
- 201571030332 扎西平措 《面向对象程序设计Java》第八周学习总结
<面向对象程序设计Java>第八周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https: ...
- 201771010118马昕璐《面向对象程序设计java》第八周学习总结
第一部分:理论知识学习部分 1.接口 在Java程序设计语言中,接口不是类,而是对类的一组需求描述,由常量和一组抽象方法组成.Java为了克服单继承的缺点,Java使用了接口,一个类可以实现一个或多个 ...
- 201771010134杨其菊《面向对象程序设计java》第八周学习总结
第八周学习总结 第一部分:理论知识 一.接口.lambda和内部类: Comparator与comparable接口: 1.comparable接口的方法是compareTo,只有一个参数:comp ...
- 201771010134杨其菊《面向对象程序设计java》第七周学习总结
第七周学习总结 第一部分:理论知识 1.继承是面向对象程序设计(Object Oriented Programming-OOP)中软件重用的关键技术.继承机制使用已经定义的类作为基础建立新的类定义,新 ...
- 201771010128 王玉兰《面象对象程序设计 (Java) 》第六周学习总结
---恢复内容开始--- 第一部分:基础知识总结: 1.继承 A:用已有类来构建新类的一种机制,当定义了一个新类继承一个类时,这个新类就继承了这个类的方法和域以适应新的情况: B:特点:具有层次结构. ...
- 201871010126 王亚涛《面向对象程序设计 JAVA》 第十三周学习总结
内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/ ...
- 201777010217-金云馨《面向对象程序设计Java》第八周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- 201871010126 王亚涛 《面向对象程序设计 (Java)》第十七周学习总结
内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/12 ...
- 马凯军201771010116《面向对象程序设计Java》第八周学习总结
一,理论知识学习部分 6.1.1 接口概念 两种含义:一,Java接口,Java语言中存在的结构,有特定的语法和结构:二,一个类所具有的方法的特征集合,是一种逻辑上的抽象.前者叫做“Java接口”,后 ...
- 周强201771010141《面向对象程序设计Java》第八周学习总结
一.理论知识学习部分 Java为了克服单继承的缺点,Java使用了接口,一个类可以实现一个或多个接口. 接口体中包含常量定义和方法定义,接口中只进行方法的声明,不提供方法的实现. 类似建立类的继承关系 ...
随机推荐
- LRU hashMap(拉链) + 双向链表 java实现
//基于 hash (拉链法) + 双向链表,LRUcache //若改为开放寻址,线性探测法能更好使用cpuCache public class LRU { private class Node { ...
- springboot入门以及配置文件
springboot入门以及配置文件 SpringBoot是什么? Spring Boot它本身并不提供Spring框架的核心特性以及扩展功能,只是用于快速.敏捷地开发新一代基于Spring框架的应用 ...
- Eviews作时间序列分析的一个实例
时间序列分析是作时间序列数据预测的一个重要部分,由于此次实验室竞赛也用到了时间序列分析,就在此说一下平稳性分析以及非平稳处理的方法: 1.判断平稳性 1.1平稳性的定义 ...
- 2019 年 GitHub 上最热门的 Java 开源项目
1.JavaGuide https://github.com/Snailclimb/JavaGuide Star 22668 [Java 学习 + 面试指南] 一份涵盖大部分 Java 程序员所需要掌 ...
- 【Linux命令】centos防火墙使用和配置
目录 firewalld iptables Linux中的防火墙(iptables,firewalld,ip6tables,ebtables).这些软件本身并不具备防火墙功能,他们的作用都是在用户空间 ...
- 详解JAVA8Stream 方法引用(基础){全}
1: Stream流 1.1 引言 1.2 流式思想概述 1.3 获取流 1.4 常用方法 1.5 练习:集合元素处理 2:方法引用 2.1 冗余的Lambda场景 2.2 方法引用符 2.3 通过对 ...
- 【Java线程与内存分析工具】VisualVM与MAT简明教程
目录 前言 VisualVM 安装与配置 本地使用 远程监控 MAT 使用场景 安装与配置 获得堆转储文件 分析堆转储文件 窥探对象内存值 堆转储文件对比分析 总结 前言 本文将简要介绍Java线程与 ...
- nginx-配置文件样例
1, 总配置文件 user nobody nobody; worker_processes ; worker_rlimit_nofile ; error_log /etc/nginx-idfa/log ...
- 转载:ubuntu下编译安装nginx及注册服务
原文地址:https://www.cnblogs.com/EasonJim/p/7806879.html 安装gcc g++的依赖库 sudo apt-get install build-essent ...
- 定时任务之SpringSchedule的注意事项
在我们现在的项目中,或多或少的都会涉及到定时任务,Spring在3.0之后引入了SpringSchedule,这让我们在使用Spring的时候,可以很容易的整合SpringSchedule.但是好用归 ...