Sending values to BD makes the application too slow

Asked

Viewed 44 times

0

I created a program in java to capture the movement of a sensor and then send the data to a database, so that later the movement is accessed by another machine in real time (or almost) elsewhere. the movement is captured perfectly, the data is sent, and the other machine can 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 becomes extremely slow, with a delay of more than 6 seconds, not only in sending, but in everything.

The code that reads and sends 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;
}

The way it is it does not send the values to the BD, because the line below is commented, so the program runs without any delay, but when this line discovers the program is extraordinarily 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 someone give me a light on how to solve this or another way to send the data that does not give this whole Leg?

  • vc can increase the interval time between updates or optimize your pojo... the tmbm hosting band interferes.

  • 1

    Are you sure you want to update the table? This seems to me much more like a new insert

  • That’s right, I don’t want to save the values, just keep an update in the database

  • @Robertojunior: The UPDATE command of the Sendframes method does not contain the WHERE clause, which causes all rows in the table to be updated. There is a single row in the table?

  • yes, there is only one row in the table

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.