Java代理的多线程 [英] Multithreading a java agent
问题描述
Java代理必须在后台上传文件,并返回上传文件的网址.在上载时,代理必须报告其进度.
A java agent has to upload a file in the background and return the Url of the uploaded file. While uploading, the agent has to report its progress.
我将代理标记为在后台客户端线程中运行.
I marked the agent to be "Run in background client thread.
我陷入了以下困境:
- 我可以从Lotus Script运行代理,并在内存文件中传递其参数,但是客户端实际上并没有在其自己的线程中运行.相反,它阻止了整个客户端.
- 我可以从公式中运行代理,但是之后我无法传递任何参数!
- 如果我使用Lotus Script并自己处理Java中的线程,那么我的线程甚至都无法启动!
我已阅读 Notes客户端不支持多线程.但是我无法使代理RunOnServer,因为它正在访问仅可用于客户端的Web服务器.
I've read that the Notes client doesn't support multithreading. But I can't make the agent RunOnServer because it is accessing a web server available only for the client.
这与另外一个我的问题.
有没有更好的解决方案?
Is there any better solution for this?
推荐答案
如果不能将代理设为RunOnServer
,则可以使用LS2J
代替代理.使用线程创建自己的类并使用其属性.
这是自定义Java Class
和Java Timer
的示例:
If you can't make the agent RunOnServer
then you can use LS2J
instead of agent. Create your own class with threading and use its properties.
Here is example with custom Java Class
and Java Timer
:
import java.util.Timer;
import java.util.TimerTask;
public class Test
{
private boolean _isOver;
private int _counter;
private Timer _timer;
private String _url;
public Test()
{
_timer = new Timer("Timer");
}
public void Start() //Add parameters here that you want to use in Java
{
_counter = 0;
_isOver = false;
_url = "";
TimerTask timerTask = new TimerTask()
{
public void run()
{
if (_counter++ == 9)
{
_isOver = true;
_timer.cancel();
_url = "http://stackoverflow.com/";
}
}
};
_timer.scheduleAtFixedRate(timerTask, 30, 5000);
}
public int getCounter() { return _counter; }
public boolean getIsOver() { return _isOver; }
public String getURL() { return _url; }
}
在LotusScript
中添加全局LS2J
变量:
(Options)
Uselsx "*javacon"
Use "MyJavaLibrary"
(Declarations)
Dim jSession As JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject
Sub Initialize
Set jSession = New JavaSession()
Set jClass = jSession.GetClass("MyClass")
Set jObject = jClass.CreateObject
End Sub
要开始使用Java object
(在Button
的LotusScript
中):
To start Java object
use (in LotusScript
of Button
):
Call jObject.Start() 'Call with parameters that you want to use in Java
要检查状态并显示进度,请使用(在Timer
的LotusScript
中):
To check state and show progress use (in LotusScript
of Timer
):
If jObject.getIsOver() Then
s$ = jObject.getURL()
'Show results
Else
i% = jObject.getCounter()
'Show progress
End If
这篇关于Java代理的多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!