Die RemoteMatlabProxyFactory.getProxy()
-Methode erstellt eine Instanz von GetProxyRequestCallback
und wartet dann, bis die proxyCreated(...)
-Methode aufgerufen wird. Wenn proxyCreated() den Thread, der die Anforderung ursprünglich erstellt hat, nicht unterbrochen hat, wartet dieser Thread daher, bis die Zeitüberschreitung erreicht wird.
Meiner Meinung nach ist dies ein Fehler in der Matlabcontrol-Bibliothek: Thread.interrupt() sollte nicht für diesen Zweck missbraucht werden, weil ein Thread, der unterbrochen wird, verschiedene Gründe haben kann und für nichts außer Signalisieren des Threads verwendet werden soll Sollte aufhören.
Dies sollte in der Matlabcontrol-Bibliothek durch Warten auf einen Mutex behoben werden.
Zum Beispiel:
class RemoteMatlabProxyFactory implements ProxyFactory {
// [...]
@Override
public MatlabProxy getProxy() throws MatlabConnectionException {
GetProxyRequestCallback callback = new GetProxyRequestCallback();
Request request = this.requestProxy(callback);
return callback.getProxy(_options.getProxyTimeout());
}
// [...]
}
private static class GetProxyRequestCallback implements RequestCallback {
private final Object _lock = new Object();
private MatlabProxy _proxy;
@Override
public void proxyCreated(MatlabProxy proxy) {
_proxy = proxy;
_requestingThread.interrupt();
}
public MatlabProxy getProxy(long timeout) throws MatlabConnectionException {
synchronized (_lock) {
if (_proxy != null) {
return _proxy;
}
try {
_lock.wait(timeout);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new MatlabConnectionException("Thread was interrupted while waiting for MATLAB proxy", e);
}
if (_proxy == null) {
throw new MatlabConnectionException("MATLAB proxy could not be created in " + timeout + " milliseconds");
}
return _proxy;
}
}
}