hilo.java
来自「solution to the simulation of the vascul」· Java 代码 · 共 60 行
JAVA
60 行
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package examen;import java.util.Random;/** * * @author ANGEL */public class hilo implements Runnable{ Thread t; Random r; int cuantos; String datos[]; int id; boolean operacion; buffer referencia; hilo(buffer obj,int id,boolean func){ r = new Random(); if(func) cuantos = 1+r.nextInt(3)+r.nextInt(3); else cuantos = 1+r.nextInt(3); operacion = func; String funcion; if(operacion) funcion = "escribira"; else funcion = "leera"; //System.out.println("HILO"+id+" "+funcion +" "+datos+" valores "); referencia = obj; this.id = id; datos = new String[cuantos]; for(int i =0;i<cuantos;i++){ datos[i] = ""+id+""; } t = new Thread(this); t.start(); } synchronized public void run(){ int i; int valor; if(operacion){ //escribirç referencia.meter_buffer(datos, cuantos, id); referencia.recorrercolas();// referencia.buscar_escritor().recorrer(); }else{ //leer referencia.sacar_buffer(cuantos,id); // referencia.valvula(); } } boolean invertir_bool(boolean valor){ return !valor; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?