为要插入数据库的数据实现队列 [英] Implementing Queue for data to be inserted in the database

查看:192
本文介绍了为要插入数据库的数据实现队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一种车辆跟踪系统,其中多个GPS设备不断使用TCP连接将其GPS位置发送到服务器. TCP通信器解码GPS位置并将该数据插入数据库.现在,TCP通信器的一个线程服务一个设备请求.解码GPS数据后,它将创建与数据库的连接,然后插入数据并释放连接. 随着设备数量的增加,与数据库(即MySQL)的并发连接数量也在增加.因此,我想实现一个队列,在该队列中,TCP通信器的每个线程会将数据推送到一端,而一个作业将从另一端获取数据,并将其插入数据库.

We are developing a vehicle tracking system in which several GPS devices keep sending their GPS locations to the server using TCP connection. The TCP communicator decodes the GPS location and inserts that data into the database. Right now, one thread of TCP communicator serves one device request. After decoding the GPS data, it creates a connection to the database and inserts the data and releases the connection. As number of devices are increasing, the number of concurrent connections to the database (which is MySQL) are also increasing. Hence, I want to implement a queue where each thread of TCP communicator will push the data to one end and one job will take data from other end and keep it inserting into the database.

有人可以建议我最好的解决方案吗?我们的应用程序基于Java,数据库为MySQL.

Can anybody suggest me the best solution to handle all this? Our application is based on Java and database is MySQL.

谢谢, 索拉比

推荐答案

您可以使用线程安全队列实现,例如

You can use a thread-safe queue implementation like ConcurrentLinkedQueue to queue the data

这篇关于为要插入数据库的数据实现队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆