Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithread support for Iso853Client? #4

Open
keyhan opened this issue Jan 20, 2016 · 4 comments
Open

Multithread support for Iso853Client? #4

keyhan opened this issue Jan 20, 2016 · 4 comments
Labels

Comments

@keyhan
Copy link

keyhan commented Jan 20, 2016

Hi, just a comment, it would make sense to make some methods like "send()" in client class synchronized. This would make them threadsafe, allowing multiple threads using the same client.

@keyhan
Copy link
Author

keyhan commented Jan 22, 2016

I have written a thread safe version that is not fully tested but I think could work. I could send it to you if you are interested.

@kpavlov
Copy link
Owner

kpavlov commented Jan 22, 2016

Thank you, @keyhan, send it please.
BTW Channel.writeAndFlush is thread-safe so why should we synchronize externally?

@keyhan
Copy link
Author

keyhan commented Jan 22, 2016

I guess it does not have any timeout handling?

I was thinking something in line with:

private synchronized void send(IsoMessage isoMessage) throws InterruptedException {
        sendAsync(isoMessage).sync().await();
    }

public void orderSend(IsoMessage isoMessage, int timeoutperiod) throws InterruptedException, TimeoutException{
        Runnable orderTask = new Runnable() {
            @Override
            public void run() {
                    try {
                        send(isoMessage);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

            }
        };
        Thread orderThread = new Thread(orderTask);
        orderThread.start();
        Thread.sleep(timeoutperiod);
        if(orderThread.isAlive()) {
            orderThread.interrupt();
            throw new TimeoutException("Thread " + orderThread.getName() + " has timed out.");
        }

    }

kpavlov added a commit that referenced this issue Feb 11, 2018
kpavlov added a commit that referenced this issue Feb 11, 2018
@VovkaSOL
Copy link

VovkaSOL commented Dec 18, 2023

don't use this netty based library with blocking thread timeout handling. For multithread use

   suspend fun suspendSendMsg(request: String): String {
        return suspendCoroutine { continuation ->
            try {
                sendMsg(request) { response ->
                    //continuation.resumeWith(Result.failure(InternalTimeoutException( "Таймаут ответа ${request!!::class.java.canonicalName} со временем ожидания ${finalTimeout.toMillis()} миллисекунд" ) ))
                    continuation.resumeWith(Result.success(response))
                }
            } catch (e: Exception) {
                LOGGER.error("что то сломалось при отправке iso сообщения", e)
                throw RuntimeException("что то сломалось при отправке iso сообщения")
            }
        }
    }
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants