Acesso a outras classes

1 resposta
S

Olá, possuo as três classe abaixo, é claro que está faltando mais coisa, mas minha dúvida é se a forma como estou acessando as listas (tarefasList e trabalhadorList) está correta, ou se terei algum problema de desempenho ou qualquer outro, por favor, me expliquem que tipo de problema se houver.

public class Gerente {

	List<Tarefas> tarefasList;
	Map<String, Trabalhador> trabalhadorList;
	GerenteEstoque gerenteEstoque;
	GerenteVendas gerenteVendas;
	
	public Gerente() {
		this.tarefasList = Collections.synchronizedList(new LinkedList<Tarefas>());
		this.trabalhadorList = Collections.synchronizedMap(new LinkedHashMap<String, Trabalhador>());
		
		this.gerenteEstoque = new GerenteEstoque(this);
		this.gerenteEstoque.start();
		
		this.gerenteVendas = new GerenteVendas(this);
		this.gerenteVendas.start();
	}
}

public class GerenteEstoque extends Thread {

	Gerente gerente;
	List<Tarefas> tarefasList;
	Map<String, Trabalhador> workersList;
	Tarefas tarefa;
	
	public GerenteEstoque(Gerente gerente) {
		this.gerente = gerente;
		this.tarefasList = this.gerente.tarefasList;
		this.trabalhadorList = this.gerente.trabalhadorList;
	}
	
	public void run() {
		while (true) {
			this.tarefa = this.tarefasList.take();
				System.out.println("Gerente estoque: recebi uma tarefas, vou enviar para o trabalhador: " + this.trabalhadorList.get());
		}
	}
}

public class GerenteVendas extends Thread {
	Gerente gerente;
	List<Tarefas> tarefasList;
	Map<String, Trabalhador> workersList;
	Tarefas tarefa;
	Trabalhador trabalhador;
	
	public GerenteVendas(Gerente gerente) {
		this.gerente = gerente;
		this.tarefasList = this.gerente.tarefasList;
		this.trabalhadorList = this.gerente.trabalhadorList;
	}
	
	public void run() {
		while (true) {
			this.trabalhador = this.tarefasList.trabalhador();
				System.out.println("Gerente Vendas: recebi um novo trabalhador: "+ this.trabalhador.getID());
		}
	}
}

Achei um exemplo parecido na internet, por isso que estou implementando desta forma, mas não sei se esta correto. Outra forma que pensei em implementar é cada gerente instanciar sua própria lista, aí cada gerente adiciona em uma deteminada lista quando desejar.

Se alguém cosneguir me ajudar.

1 Resposta

ViniGodoy

Não duplique tópicos.

Na dúvida sobre qual fórum abrir, ou caso queira mudar de fórum, peça para um moderador mover seu tópico.
Tenha paciência também, pois o GUJ é bem menos acessado no domingo. Muitos programadores também descansam. :slight_smile:

Esse tópico será trancado.

Criado 25 de março de 2012
Ultima resposta 25 de mar. de 2012
Respostas 1
Participantes 2