从多个线程读取相同的ResultSet [英] Reading the same ResultSet from multiple threads

查看:104
本文介绍了从多个线程读取相同的ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中,我有一个定义表,该表在启动时会从应用程序中读取一次.该定义表很少更改,因此有必要对其进行一次读取并在每次更改时重新启动应用程序.

In the database, I have a definition table that is read from the application once upon starting. This definition table rarely changes, so it makes sense to read it once and restart the application every time it changes.

但是,在读取表(放入ResultSet)之后,将由运行在各自线程中的多个处理程序读取该表.

However, after the table is read (put into a ResultSet), it will be read by multiple handlers running in their own threads.

您如何建议完成此任务?

How do you suggest to accomplish this?

我的想法是填充CachedRowSet,然后在每次收到新请求时为每个处理程序创建此集合的副本(通过createCopy()方法).

My idea was to populate a CachedRowSet, and then create a copy of this set (through the createCopy() method) for each handler every time a new request comes.

您认为这是明智的吗?这样可以提供良好的性能吗?

Do you think this is wise? Does this offer a good performance?

谢谢.

推荐答案

我认为这是一种将配置表读入静态数据结构(ConcurrentHashMap),然后让线程进行查找的模式.

I think it is a pattern to read the configuration table into a static data structure (ConcurrentHashMap) and then let the threads to look it up.

通过从Servlet.init()填充参考映射,可以确保启动时没有写争用-保证每个servlet执行一次.

You can ensure that there is no write race at startup by populating the reference map from a Servlet.init() - it is guaranteed to execute once per servlet.

这篇关于从多个线程读取相同的ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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