为什么在包含Servlet和Java中的“worker”线程的web-app中使用ServletContext对象(Why use the ServletContext object in a web-app containing servlets and “worker” threads in Java)
我目前有一个Web应用程序,我有Servlet读取和写入
ServletContext
属性,我有“工作”线程(守护进程线程),它们在启动时初始化并且当前保持为ServletContext
对象的成员。 出于几个原因,我正在考虑转而使用“实现Runnable
”,而且我很困惑这样一个事实,即我需要一个公共资源,servlet和非servlet可以用来相互交流,我觉得我有点卡在整个ServletContext
范例中。 我会很感激,如果有人可以提供点为什么要使用ServletContext
(我的方式或另一种方式),我也想只使用一个单身类,将在启动时初始化,将是线程安全的,我会只需通过它传递servlet和非servlet的所有通信。 你怎么看?谢谢
I currently have a web-app where I have Servlets reading and writing to the
ServletContext
attributes and I have "working" Threads (Daemon threads) which get initialized on startup and currently hold as a member theServletContext
object. For a couple of reasons I'm thinking of moving to "implementRunnable
" instead and I'm kind of stuck with the fact that I need a common resource that servlets and non-servlets can use to talk with each other and I feel I'm a bit stuck in the wholeServletContext
paradigm. I'd appreciate it if someone could provide points on why to use theServletContext
(my way or another way) and also I'm thinking to just use a singleton class which will be initialized on startup and will be thread safe and I'll just route all communication of the servlets and non-servlets through it. What do you think?Thanks
原文:https://stackoverflow.com/questions/1517420
最满意答案
select name, MIN(ID) from aCertainTable group by name
select name, MIN(ID) from aCertainTable group by name
相关问答
更多-
select name, MIN(ID) from aCertainTable group by name select name, MIN(ID) from aCertainTable group by name
-
SELECT name, color FROM new_dogs EXCEPT SELECT name, color FROM name_color_pairs 要么 SELECT name, color FROM new_dogs nd WHERE NOT EXISTS (SELECT name, color FROM name_color_pairs ncp WHERE (ncp.name = nd.name) AND (ncp.color = nd.color)) 或者最后(应该到处工作): SE ...
-
SELECT INTO查询(SELECT INTO query)[2022-11-13]
SELECT history_number = IDENTITY(INT,1,1), ... etc... INTO NewTable FROM ExistingTable WHERE ... 您可以使用ROW_NUMBER而不是身份,即ROW_NUMBER()OVER(ORDER BY) SELECT history_number = IDENTITY(INT,1,1), ... etc... INTO NewTable FROM ExistingTable WHERE ... You ... -
我如何编写这个SQL查询?(How do I write this SQL query?)[2022-07-17]
这可以做到这一点: SELECT * FROM MyTable WHERE parentId = '001' AND childId = (SELECT MAX(childId) FROM MyTable WHERE parentId = '001') This aught to do it: SELECT * FROM MyTable WHERE parentId = '001' AND childId = (SELECT MAX(childId) FROM MyTable WHERE parentId ... -
使用subquery : select * from table t where event_timestamp = (select max(event_timestamp) from table where event_name = t.event_name); 而且,一般来说最有效的方法是使用排名函数(如果支持) select * from ( select *, ...
-
需要帮助编写SQL查询?(Need help to write a SQL query?)[2021-09-22]
使用Arnold Fribble在这个帖子中回答的分割函数 Create FUNCTION dbo.Split (@sep char(1), @s varchar(512)) RETURNS table AS RETURN ( WITH Pieces(pn, start, stop) AS ( SELECT 1, 1, CHARINDEX(@sep, @s) UNION ALL SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s ... -
您应该使用用于聚合的子查询来编写此查询: select p.*, c.car_brands, m.mobile_brands from person p left join (select c.person_id, array_agg(cd.car_brand) as car_brands from car_details c group by c.person_id ) c on c.person_id = p.id left join (s ...
-
多对多的选择查询(many to many select query)[2023-12-04]
这应该是相当接近你正在寻找 SELECT product.* FROM product JOIN ProductCategory ON ProductCategory.ProductID = Product.product_id JOIN #my_temp ON #my_temp.category_id = ProductCategory.CategoryID 编辑 正如在评论中指出的那样,这将产生出现在多个类别中的产品的重复。 若要更正此问题,请在列列表前指定DISTINCT 。 我已将所有 ... -
如何编写高效的sql查询来从多个表中进行选择?(How to write efficient sql query to select from multiple tables?)[2022-12-16]
尝试 select p.Title, stuff((select ', ' + i.ImageName from Images i where i.ListingID = p.ListingID for xml path('')),1,2,'') as Images, stuff((select ', ' + t.Tag from Tags t where t.ListingID = p.ListingID for xml path('')),1,2,'') as Tags from Listing p ... -
如果您尝试更新集合中的所有记录,则可以编写如下查询: UPDATE message_queue mq INNER JOIN ( SELECT NULL AS msg_id, NULL AS total, NULL AS found FROM dual WHERE ( @total :=0 OR @found :=0 ) UNION SELECT msg_id, @total AS total, @found :=1 ...