访问当前进程句柄

编程入门 行业动态 更新时间:2024-10-25 11:25:18
本文介绍了访问当前进程句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我们的 RCP 4 应用程序中,由于没有更多可用的句柄,我们抛出了 SWT 异常.这可能是由资源泄漏或其他 3rd 方应用程序运行引起的.我们无法在开发中重现此问题,因此我们希望记录任何可能有助于我们在未来解决此问题的信息.

In our RCP 4 application we have had SWT exceptions thrown caused by there being no more handles available. This could be caused by a resource leak or by other 3rd party applications running. We are unable to reproduce this in development so we would like to log any information that could possibly help us fix this in the future.

我们想获取有关句柄的信息.例如.总句柄及其用途,例如图像、字体和合成.

We would like to get information about the handles. E.g. Total handles and what they are used for such as images, fonts, and composites.

我一直在寻找这个,我正在努力寻找任何关于如何在 Java 中完成的信息.我们可以执行命令行获取信息,但这并不是一种很好的方式.

I've been looking this up and I'm struggling to find anything on how this can be done in Java. We could execute command line for the information but that doesn't feel like a great way of doing it.

通过 Handles 我指的是 Windows 上的 GDI Handles 和 User Handles.

By Handles I'm referring to GDI Handles and User Handleson Windows.

如何做到这一点?

plugin.xml

<plugin> <extension id="product" point="org.eclipse.core.runtime.products"> <product application="org.eclipse.e4.ui.workbench.swt.E4Application" name="appid"> <property name="modelResourceHandler" value="bundleclass://a.model.resource.handler.ModelResourceHandler"> </property> </product> </extension> </plugin>

推荐答案

Eclipse Sleak 可以监控 SWT 所做的分配 - 代码是 这里.

Eclipse Sleak can monitor the allocations made by SWT - the code is here.

然而,这需要使用启用跟踪的 DeviceData 对象创建 SWT Display.标准的 E4Application 不这样做.

However this requires the SWT Display to be created with a DeviceData object enabling tracking. The standard E4Application doesn't do this.

所以要使用它,您需要使用您自己的扩展 E4Application 的应用程序类 - 类似于:

So to use this you need to use your own application class extending E4Application - something like:

import org.eclipse.e4.ui.internal.workbench.swt.E4Application; import org.eclipse.swt.graphics.DeviceData; import org.eclipse.swt.widgets.Display; public class MyApplication extends E4Application { /** Enable tracking */ private static final boolean TRACKING = true; /** Enable debug */ private static final boolean DEBUG = false; public MyApplication() { super(); } @Override public Display getApplicationDisplay() { Display current = Display.getCurrent(); if (current == null) { if (TRACKING || DEBUG) { DeviceData data = new DeviceData(); data.tracking = TRACKING; data.debug = DEBUG; current = new Display(data); if (data.tracking) { Sleak sleak = new Sleak(); sleak.open(); } } else { current = new Display(); } } return super.getApplicationDisplay(); } }

您需要在 plugin.xml 中声明此应用程序:

You will need to declare this application in the plugin.xml:

<extension id="application" name="Application name" point="org.eclipse.core.runtime.applications"> <application cardinality="singleton-global" thread="main" visible="true"> <run class="your.package.MyApplication"> </run> </application> </extension>

在 plugin.xml 中更改您的产品声明以使用此应用程序而不是 org.eclipse.e4.ui.workbench.swt.E4Application.所以像:

Change your product declaration in the plugin.xml to use this application instead of org.eclipse.e4.ui.workbench.swt.E4Application. So something like:

<extension id="product" point="org.eclipse.core.runtime.products"> <product name="%product.name" application="my.plugin.application">

再举一个例子,以下是我的一个 e4 RCP 中经过测试的有效 plugin.xml 的一部分:

As a further example the following is part of a tested, working plugin.xml from one of my e4 RCPs:

<plugin> <extension id="application" name="%app.name" point="org.eclipse.core.runtime.applications"> <application cardinality="singleton-global" thread="main" visible="true"> <run class="greg.music.e4.rcp.MusicApplication"> </run> </application> </extension> <extension id="product" point="org.eclipse.core.runtime.products"> <product name="%product.name" application="greg.music.e4.rcp.application"> ...... properties </product> </extension>

这是一个 ID 为 greg.music.e4.rcp 的插件.这定义了一个 ID 为 greg.music.e4.rcp.application 的应用程序和一个 ID 为 greg.music.e4.rcp.product

This is in a plugin with id greg.music.e4.rcp. This defines an application with id greg.music.e4.rcp.application and a product with id greg.music.e4.rcp.product

更多推荐

访问当前进程句柄

本文发布于:2023-11-17 11:46:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:句柄   进程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!