1
Good morning Personal.
I made a java application that at certain times it executes a database query and generates a text file.
The application is working right in the schedules that were programmed, however in the time it stands still it is consuming a lot of memory (around 1300 MB)
I think this is not normal because some desktop and wev applications that would have to have a higher consumption are not even close to what this application is consuming.
If anyone has an idea of what may be or any fix of the problem follows below the code.
private static String fileStream = "C:\\Users\\genesys\\Documents\\RM\\arq.txt";
//private static String fileStream = "C:\\Users\\Vostro-3300\\Desktop\\A comparar\\arq.txt";
public static void main(String[] args) throws IOException {
boolean fim = false;
while(fim == false){
Calendar calendario = new GregorianCalendar();
Date dt = calendario.getInstance().getTime();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
String dtF = df.format(dt);
if(dtF.equals("06:00:00")||dtF.equals("06:00:01")||dtF.equals("06:00:02")||dtF.equals("06:00:03")){
try{
// função para envio de email
}catch(Exception ex){
ex.printStackTrace();
}
}
if(dtF.equals("18:00:01") ||dtF.equals("18:00:02")||dtF.equals("18:00:03")||dtF.equals("11:25:00")||dtF.equals("11:25:01")||dtF.equals("11:25:02")){
try{
Conecta c = new Conecta();
ArrayList<Dados> lista = c.listar();
FileWriter arq = new FileWriter(fileStream);
PrintWriter print = new PrintWriter(arq);
print.println("CCODCOLIGADA;CODSECAO;DESCRICAO;NROCENCUSTOCONT;NOME;CODFUNCAO;NOME1;CHAPA;NOME2;DTNASCIMENTO;JORNADA;SALARIO;SEXO;DATAADMISSAO;DATADEMISSAO;STATUS;TIPOCONTRATO;DESCRICAOFUNCAO;GRAUINSTRUCAO;CPF;PISPASEP;RG;CTPS;ESTADOCIVIL;ENDERECO;BAIRRO;CIDADE;ESTADO;CEP;TELEFONE;EMAIL;TIPOADMISSAO");
for(Dados d: lista){
print.println(d.getCodLigada()+";"+d.getCodSecao()+";"+d.getDescricao()+";"+d.getNroCenCustoCont()+";"+d.getNomeCent()+";"+d.getCodFuncao()+";"+d.getNomeFunc()+";"+d.getChapa()+";"+d.getNome()+";"+d.getDtNasc()+";"+d.getJornada()+";"+d.getSalario()+";"+d.getSexo()+";"+d.dtAdmissao+";"+d.getDtDemisao()+";"+d.getStatus()+";"+d.getContratoTipo()+";"+d.getCargoDesc()+";"+d.getGrauInstrucao()+";"+d.getCpf()+";"+d.getPisPasep()+";"+d.getRg()+";"+d.getNmrCtps()+";"+d.getEstadoCivil()+";"+d.getEndreco()+";"+d.getBairro()+";"+d.getCidade()+";"+d.getEstado()+";"+d.getCep()+";"+d.getTelefone()+";"+d.getEmail()+";"+d.getTipoAdmissao());
}
arq.close();
}
catch(Exception e){
try{
// função para envio de email
}catch(Exception ex){
ex.printStackTrace();
}
}
}else{
}
}
}
Isn’t it simpler to schedule a task in the OS to run this program at certain times? Depending on the time, you initialize the program with a different argument (and you can pick it up from
args
).– Renan Gomes
@Nan may be an option but in the future I will need some information that this tool will produce at random times.
– Diego Ferreira de Oliveira