Lector Escritor /Semáforos Java

Páginas: 3 (534 palabras) Publicado: 9 de diciembre de 2012
package semaphoreexample;

/**
*
* @author RICHARD MEJIA
*/

import java.util.concurrent.locks.*;
import java.util.concurrent.Semaphore;

public class SemaphoreExample {

int i = 0;public static void main (String[] args) {
clsEscritor es= new clsEscritor(2000);
clsEscritor1 es1= new clsEscritor1(2000);
clsLector L1= new clsLector(2000);
clsLector L2= newclsLector(8000);
clsLector L3= new clsLector(10000);

es.start();
es1.start();
L1.start();
L2.start();
L3.start(); } }
package semaphoreexample;

importjava.io.*;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
* To change this template, choose Tools | Templates
* and open thetemplate in the editor.
*/

/**
*
* @author publico
*/
public class T {
private String Directo="+";
Semaphore s= new Semaphore(0);///////////////////////////////////////////////////////////////////////
public String Abrira(String Dir){

String Llevo_Texto = new String("");
try{
FileReader Carga_Escritura = new FileReader(Dir);
BufferedReader Lev_Text = newBufferedReader(Carga_Escritura);
String Llevo_Otro = new String();

while((Llevo_Otro = Lev_Text.readLine())!=null){

if(Llevo_Texto == null){
Llevo_Texto = Llevo_Otro;
}
if(Llevo_Texto !=null){
Llevo_Texto = Llevo_Texto + Llevo_Otro + "\n";
}
}

Lev_Text.close();
Carga_Escritura.close();
}

catch(FileNotFoundException e){
System.out.println("El Archivo No se encontro");
}catch(IOException e){
System.out.println("ERROR: No se puede leer el archivo");
}
return Llevo_Texto;
}

//Para llamar a este metodo seria: VarInstanceada.Abrira(“C:\entrada.txt”);

//Sise desea escribir en un archivo de texto, seria:
//////////////////////////////////////////////////////////////////////
public boolean Guardara(String mas, String Dir){
if( !"".equals(Dir)){...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Semaforo En Java
  • lectores y escritores
  • propositos de los lectores y escritores
  • Contrucción De Lectores Y Escritores
  • Rol Del Lector Y El Escritor
  • ENSAYO: CONSTRUCCIÓN DE LECTORES Y ESCRITORES.
  • las prosas del escritor y de lector
  • El escritor que fue primero lector

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS