I have only one view in my plugin. And before the view starts, I want to make sure my server has been started as the view will be started depending on server. Currently, I start my server in Display thread
as Display.getDefault().syncExec()
, while starting my plugin - start(BundleContext context)
.
我的插件中只有一个视图。在视图开始之前,我想确保我的服务器已启动,因为视图将根据服务器启动。目前,我在Display线程中启动我的服务器作为Display.getDefault()。syncExec(),同时启动我的插件 - 启动(BundleContext上下文)。
Sometimes, I see a deadlock between bundleloader
and this thread. Bundleloader
is waiting for my plugin to start, whereas my plugin start is waiting for the server to start because of syncExec()
call.
有时候,我看到了bundleloader和这个线程之间的死锁。 Bundleloader正在等待我的插件启动,而我的插件启动是因为syncExec()调用而等待服务器启动。
How can I achieve this? Is there any way to perform a particular task before my view start?
我怎样才能做到这一点?在我的视图开始之前有没有办法执行特定任务?
2 个解决方案
#1
If you are not using E4 and your view extends org.eclipse.ui.part.ViewPart
, there is an init()
如果你没有使用E4并且你的视图扩展了org.eclipse.ui.part.ViewPart,那么有一个init()
void init(IViewSite site) throws PartInitException
which is called before createPartControl(Composite parent)
.
在createPartControl(Composite parent)之前调用。
Maybe that helps?
也许这有帮助吗?
#2
Try to avoid Display.getDefault().syncExec()
; this call can block the UI - Eclipse will freeze without any indication why.
尽量避免使用Display.getDefault()。syncExec();这个调用可以阻止UI - Eclipse将冻结而没有任何指示原因。
Instead, you should start a background thread / worker job. When the worker is done (your server has been started), you should send a signal to the view.
相反,您应该启动后台线程/工作人员作业。当工作人员完成(您的服务器已启动)时,您应该向视图发送信号。
The view should initialize itself with "Starting server...". When the signal arrives, you can update the UI to display the actual content. That way, you don't have to block and the user will see why they don't see anything :-) You can also display error messages when you couldn't start the server, etc.
视图应使用“正在启动服务器...”进行初始化。信号到达时,您可以更新UI以显示实际内容。这样,您不必阻止,用户将看到他们没有看到任何内容的原因:-)您还可以在无法启动服务器时显示错误消息等。
#1
If you are not using E4 and your view extends org.eclipse.ui.part.ViewPart
, there is an init()
如果你没有使用E4并且你的视图扩展了org.eclipse.ui.part.ViewPart,那么有一个init()
void init(IViewSite site) throws PartInitException
which is called before createPartControl(Composite parent)
.
在createPartControl(Composite parent)之前调用。
Maybe that helps?
也许这有帮助吗?
#2
Try to avoid Display.getDefault().syncExec()
; this call can block the UI - Eclipse will freeze without any indication why.
尽量避免使用Display.getDefault()。syncExec();这个调用可以阻止UI - Eclipse将冻结而没有任何指示原因。
Instead, you should start a background thread / worker job. When the worker is done (your server has been started), you should send a signal to the view.
相反,您应该启动后台线程/工作人员作业。当工作人员完成(您的服务器已启动)时,您应该向视图发送信号。
The view should initialize itself with "Starting server...". When the signal arrives, you can update the UI to display the actual content. That way, you don't have to block and the user will see why they don't see anything :-) You can also display error messages when you couldn't start the server, etc.
视图应使用“正在启动服务器...”进行初始化。信号到达时,您可以更新UI以显示实际内容。这样,您不必阻止,用户将看到他们没有看到任何内容的原因:-)您还可以在无法启动服务器时显示错误消息等。