【问题标题】:JAVA thread allocation?JAVA线程分配?
【发布时间】:2016-01-22 14:55:27
【问题描述】:

我的程序在 Eclipse 中运行,所有进程都将在一个线程中完成。将其部署到客户端机器时遇到问题(我不确定机器的配置)。

线程在处理过程中突然从btpool0-1变为`btpool0-7。我确定我没有在编码中创建任何线程。

我想知道这种行为有什么原因吗??

提前致谢!!

=======在这里登录======================================= ===============

2016-01-20 12:03:58.784 [btpool0-1] 信息 hk.com.xx.sys.service.impl.BargeVoyageServiceImpl - 结束提交请求 到 nSys 在 saveAndSynchronize

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.persistence.TransactionCoordinator - 之前刷新 在线程 2055564603 中提交事务 id 1656368712

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.persistence.DefaultEntityManager - 运行刷新 线程中自定义框架管理器 1801910956 的委托 481556314 会话中的 2055564603 事务中的 1798587502 上下文中的 2028663310 880330942 2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.ro.security.remote.RemotecustomFrameworkManager - 运行 为 customFramework 管理器 146387751 的委托 1470155242 刷新 会话 2099793559 中的线程 2055564603 事务 1484449171 中 上下文 1631574962

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.persistence.TransactionCoordinator - 提交 线程 2055564603 中的事务 id 1656368712

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.persistence.DefaultcustomFrameworkManager - 已提交 customFramework 管理器的委托 481556314 的事务 线程中的 1801910956 会话中的 2055564603 事务中的 1798587502 2028663310 在上下文 880330942

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.persistence.DefaultcustomFrameworkManager - 已关闭 线程中为 customFramework manager 1801910956 委托 481556314 2055564603 在会话 1798587502

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.ro.security.remote.RemotecustomFrameworkManager - customFramework 的委托 1470155242 的已提交事务 经理 146387751 在线程 2055564603 在会话 2099793559 在 上下文 1631574962 中的事务 1484449171

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.ro.security.remote.RemotecustomFrameworkManager - 自定义框架管理器 146387751 的已关闭委托 1470155242 会话 2099793559 中的线程 2055564603

2016-01-20 12:03:58.877 [btpool0-1] 调试 customFramework.persistence.TransactionCoordinator - 提交 线程 2055564603 中的事务结束 id 1656368712

2016-01-20 12:03:58.877 [btpool0-1] 信息性能 - hk.com.xx.sys.service.BargeVoyageService 方法 saveAndSynchronizeForPeakMode - 经过的时间是 687 毫秒。

2016-01-20 12:03:59.190 [btpool0-1] 调试 HK.com.xx.ro.security.ThreadSecurityContext - stack.size() = 1;指数 = 0

2016-01-20 12:03:59.252 [btpool0-7] 信息 customFramework.service.http.HttpServiceHandlerFactory - 调用 服务 hk.com.xx.sys.service.BargeVoyageService 方法 savePeakBargeVoyageInBatch

2016-01-20 12:03:59.252 [btpool0-7] 调试 customFramework.service.http.HttpServiceHandlerFactory - 服务 对象 =

2016-01-20 12:03:59.252 [btpool0-7] 调试 customFramework.service.ServiceInterceptorFactory - 调用方法 savePeakBargeVoyageInBatch 与事务属性 = REQUIRED

2016-01-20 12:03:59.252 [btpool0-7] 调试 customFramework.persistence.TransactionCoordinator - 执行 交易属性 = REQUIRED

2016-01-20 12:03:59.252 [btpool0-7] 调试 customFramework.persistence.TransactionCoordinator - 开始交易 id 1656368712 在线程 1377751019

2016-01-20 12:03:59.252 [btpool0-7] 调试 customFramework.persistence.DefaultcustomFrameworkManager - 创建 线程中自定义框架管理器 1801910956 的委托 1334851109 1377751019 会话 80928754 上下文 812419927

【问题讨论】:

    标签: java multithreading hibernate


    【解决方案1】:

    好吧,你确实使用了一个池 - btpool0-7 读取为池 #0 的线程 #7。现在,这不是意味着您已经启动了 6 个线程 - 它只是意味着您的池的大小至少有 8 个线程大,并且出于某种随机原因选择线程 #7 来启动工作。这可能是由于多种原因,我不会在这里一一列举,我只想说 a)它是良性的,b)你不应该关心这个数字,只是在记录期间它保持不变。

    【讨论】:

    • 为什么调用其他方法时线程数会改变??我的开发环境中没有这个问题。我问这个问题是因为程序中使用了 threadlocal variable。线程数改变导致一些数据不同步的问题。
    • 具有不同线程 ID 的第一条日志行提到了“customFramework.service.http.HttpServiceHandlerFactory”——所以也许您正在那里处理一些 HTTP 请求?
    • 我不确定什么时候会调用 http 请求,因为大部分流程都是由公司框架处理的。至少我没有在编程中调用http请求。我想问几个问题.. 1.这意味着如果通过http请求调用该方法,将创建一个新线程??? 2. 不同的操作系统是否可能具有不同的线程行为?这是因为在我的开发环境中,所有进程都在同一个线程中完成。谢谢!
    • 1) 很可能,线程已经创建 - 看看您是否可以连接到 VisualVM 以查看线程名称。 2) 是的;您还可以使用不同版本的 Java 并使用不同的 HashMap 实现来更改线程的顺序;您还可以在开发和生产中使用不同的池大小。然而,你为什么在乎?您的 ThreadLocal 应该隔离线程;如果您需要跨线程访问,请使用某种标识符。
    • 当值存储在线程本地的 saveAndSynchronizeForPeakMode 方法 [btpool0-1] 时,我们面临一个问题。之后,我们必须在 savePeakBargeVoyageInBatch [btpool0-7] 处获取值。问题是......由于线程已更改,我们无法获取该值。正如您所提到的, threadlocal 隔离了线程。谢谢你的帮助~~~!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 2010-12-25
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    相关资源
    最近更新 更多