java - 多线程 Java 代理

标签 java multithreading lotus-domino lotusscript lotus-formula

java代理必须在后台上传文件并返回上传文件的Url。上传时,代理必须报告其进度。

我将代理标记为“在后台客户端线程中运行”。

我陷入了以下困境:

  • 我可以从 Lotus Script 运行代理并在内存文件中传递其参数,但客户端实际上并不在自己的线程中运行。相反,它会阻止整个客户端。
  • 我可以通过公式运行代理,但无法传递任何参数!
  • 如果我使用 Lotus Script 并在 Java 中自行处理线程,我的线程甚至无法启动!

我读到 Notes client doesn't support multithreading 。但我无法使代理成为 RunOnServer,因为它正在访问仅供客户端使用的 Web 服务器。

这与 another question of mine 相关顺便说一下。

有没有更好的解决方案?

最佳答案

如果您无法使代理RunOnServer那么您可以使用LS2J代替代理。使用线程创建您自己的类并使用其属性。
以下是自定义 Java ClassJava 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 对象,请使用(在 ButtonLotusScript 中):

Call jObject.Start() 'Call with parameters that you want to use in Java

要检查状态并显示进度,请使用(在 TimerLotusScript 中):

If jObject.getIsOver() Then
    s$ = jObject.getURL()
    'Show results
Else        
    i% = jObject.getCounter()
    'Show progress
End If

关于java - 多线程 Java 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24739811/

相关文章:

lotus-notes - Domino 线程中的 View 安全吗?

xpages - 运行并行代理调用时 Domino 崩溃

lotus-domino - 在 IBM Domino 中,如何从代理和脚本库中检索 Java 类文件

c++ - std::condition_variable::notify_one() 不唤醒等待线程

java - 中断整个线程

java - Spring Autowiring Autowiring 的bean中的属性

java - 如何排除 bouncycaSTLe weblogic 12c 库

c# - 是否允许在线程之间缓存/重用 Thread.GetNamedSlot?

java - Gson.json() 解析json文件时返回null

java - 在 Java 中打开大型现有 Excel 文档