You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Dupont jean <do...@yahoo.fr> on 2007/04/21 01:26:41 UTC

Issue with resource locking

Hi there,

I'm having an issue with a protocol handler i wrote. The handler acquires a lock in the first stages of the protocol communication, then multiple messages are exchanged between client and server and when the client decides to put an end to the communication server should release the acquired lock. The problem is multiple threads are used to service the protocol and the thread that releases the lock isn't the one that acquired the lock which results in an IllegalStateMonitorException. 

How can i configure Mina to use a thread pool but to always use the same thread in a session as this will prevent the lock problem ?

Here's the code i actually use to configure mina :

---
        ByteBuffer.setUseDirectBuffers(false);
        ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
        
        IoAcceptor acceptor = new SocketAcceptor(Runtime.getRuntime()
                .availableProcessors() + 1, Executors.newCachedThreadPool());
        IoAcceptorConfig config = new SocketAcceptorConfig();
        ((SocketAcceptorConfig) config).setReuseAddress(true);
        DefaultIoFilterChainBuilder chain = config.getFilterChain();
        
        chain.addLast("codec", new ProtocolCodecFilter(
                new TextLineCodecFactory(Charset.forName("UTF-8"))));

        acceptor.bind(new InetSocketAddress(PORT), new Pop3ProtocolHandler(true),
                config);
---


Regards,
Edouard De Oliveira


 



      
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses 
http://fr.answers.yahoo.com

Re: Issue with resource locking

Posted by Niklas Therning <ni...@trillian.se>.
Dupont jean wrote:
> Hi there,
>
> I'm having an issue with a protocol handler i wrote. The handler acquires a lock in the first stages of the protocol communication, then multiple messages are exchanged between client and server and when the client decides to put an end to the communication server should release the acquired lock. The problem is multiple threads are used to service the protocol and the thread that releases the lock isn't the one that acquired the lock which results in an IllegalStateMonitorException. 
>
> How can i configure Mina to use a thread pool but to always use the same thread in a session as this will prevent the lock problem ?
>
> Here's the code i actually use to configure mina :
>
> ---
>         ByteBuffer.setUseDirectBuffers(false);
>         ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
>         
>         IoAcceptor acceptor = new SocketAcceptor(Runtime.getRuntime()
>                 .availableProcessors() + 1, Executors.newCachedThreadPool());
>         IoAcceptorConfig config = new SocketAcceptorConfig();
>         ((SocketAcceptorConfig) config).setReuseAddress(true);
>         DefaultIoFilterChainBuilder chain = config.getFilterChain();
>         
>         chain.addLast("codec", new ProtocolCodecFilter(
>                 new TextLineCodecFactory(Charset.forName("UTF-8"))));
>
>         acceptor.bind(new InetSocketAddress(PORT), new Pop3ProtocolHandler(true),
>                 config);
> ---
>   
What is it that you are protecting with your lock and what kind of lock are you using? One of the java.util.concurrent.locks.Lock
implementations?

You seem to be implementing a POP3 server. Are you perhaps using the
lock for preventing concurrent access to a POP3 user's mailbox? 

If possible, please post the code of your IoHandler implementation.



/Niklas

-- 
Niklas Therning
www.spamdrain.net