Sending values to DB leaves application too slow

0

I have created a java program to capture the movement of a sensor and then send the data to a database, so that the movement is accessed by another machine in real time (or almost) from another location. the movement is captured perfectly, the data is sent, and the other machine is able to read the data at the time the data is updated in the database. The problem is that when I start sending the data to the database, the program gets extremely slow, with a delay of more than 6 seconds, not only in sending, but in everything.

The code that reads and submits is as follows:

public static ScheduledExecutorService StartPrintFrames (final Device device)
{
    isPrinting = true;
    isPaused = false;
    final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
    ses.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                int[] x = new int[4];
                x = methods.GetFrame(device);
                tela.AtualizeBar(x[0],x[1],x[2],x[3]);
                tela.AtualizeHeartRate(x[3]);
                //ConnectionToDB.instance.SendFrames(x[0],x[1],x[2],x[3]);
                } 
            catch (BPException ex) 
            {
                Logger.getLogger(Classe.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }, 0, 1, TimeUnit.MILLISECONDS);
    printFrames = ses;
    return ses;
}

As it is, it does not send the values to the DB, because the line below is commented, so the program runs without any delay, but when I uncomment this line the program gets extremely slow

//ConnectionToDB.instance.SendFrames(x[0],x[1],x[2],x[3]);

The SendFrames () method is as follows:

public void SendFrames(int v1, int v2, int v3, int v4)
{
    try
    {
        //frame 1,2,3,4
        String request = "UPDATE Tabela SET ent1 = ?, ent2 = ?, ent3 = ?, ent4 = ?;";
        PreparedStatement pst = connection.prepareStatement(request);
        pst.setInt(1,v1);
        pst.setInt(2,v2);
        pst.setInt(3,v3);
        pst.setInt(4,v4);
        pst.execute();
    } 
    catch (Exception e)
    {
        System.out.println(e);
    }
}

Can anyone give me a light on how to solve this or another way of sending data that does not give this whole leg?

    
asked by anonymous 23.10.2017 / 00:57

0 answers