Socket in pooled thread

I am using a ExecutorService (fixed thread pool) for client threads. Every client thread creates a socket connection. I was wondering if there is a way to keep the socket connection open for every pooled thread or if I have to have an extra pool for those socket connections.

Yes, just put it somewhere where the Runnables can find it.

Similar Messages

  • Sharing socket object between threads - Is any sync required?

    For example, a thread receives (listens) datagram packets at incoming socket and forwards them downstream through another datagram socket. Another thread listens packets at this second socket and forwards the data via the first socket. It is possible that two threads invoke methods of the same socket (one is receiveng while another is sending). This situation is not described in the DatagramSocket manual. I beleive there is underlying synchronization at the OS kernel level. Can I relay on it? Thanks.

    I expected some critics for using old plain sockets instead of nio :)You should use NIO if you have hundreds of connections. If you have a small number of connections and want a simple implementation use blocking IO as you have.
    If you can have different
    threads reading or writing at once eg two readingor
    two writing then you need to use synchronisation.Shouldn't this be stated by the API designers somewhere?It is probibly covered in a tutorial or example somewhere.
    You have a different input and output stream. There is a lock on each. This is your best hint.
    Theoretically, nothing prohibits sending UDP packets in race conditions.
    In fact, this is what my program
    does - it respondes to different clients using one
    (server) datagram socket. The responses are produced
    by multiple threads. I suppose that java does not
    involve any state variables; thus, beleive that the
    system can accomplish the synchronisation unnecesary
    at the application level.That depends on how you build and send your messages. If each part of the message can be sent in one hit and the order does not matter you are fine.
    If you have a single object shared between threads, then all members are shared, not just static variables.

  • Monitering Multiple Sockets in one thread

    Hi all
    i have a problem.....i want to create and moniter multiple sockets BUT Due to resourse problems i cannot create as many threads. I want to use multiple sockets in one thread.
    Cani do something where i can have array of sockets and poll for data in a single while loop for all the sockets...OR u may suggest another solution for my porblem of using multiple sockets in one thread.
    thanks in advance
    Sai Burra

    Here's a pseudocode solution I've used:
    Create a thread to listen to incoming connections. Upon incoming connection, add the socket and inputstream to the incoming messages listener thread.
    Create a threadpool for outgoing messages.
    Create a thread to process incoming messages.
    Incoming message listener thread:
    Create a hashtable of sockets. Socket is the key, inputstream is the value.
    Loop through each key, and assuming BufferedReader input you can poll by using (input.isReady()). If isReady() returns true, that means there is data on the stream coming in, so you'll need to process it.
    After processing the data, call a thread from your outgoing messages threadpool to send the response - in case there is blocking, you'll still be able to process the rest of your data.
    Sleep the incoming messages thread for 200 ms (300-400ms is quite adequate for real time processing I've found, at least the slowdown isn't noticable).
    This should work for what you're talking about.

  • Server socket programming and thread

    hello,
    briefly this is what i have sought out to do : the server waits for the client indefinitely,upon a client requesting for service by writing a service id into the socket, a new thread of the type id as read by the server which is a sub-class of the Server (main-class) is exec'd.
    the problem as i understand is that the client can send as much of data as it desires to the server and the thread can read the data it receives by the clients.the server(thread) fails to write reply to the client;eventhough out.write() is successful;the client is blocked in read() indefinitely.is it because of the thread which runs at a different port the client does not know and the server is not redirecting response to the client.
    how do i read what the server(thread) writes onto the socket from the clients.

    thanks again,just check out this code please
    public class Server extends Thread //create a multi-threaded server
        /* *Creates a new instance of Server  */
        String                           serverAddr=CodeServer.ServerRun.SERVER_IP_ADDR;
        int                              serverPortNum=CodeServer.ServerRun.SERVER_TCP_PORT;   
        ServerSocket                     sSock;
        Socket                           cSocket;
        int                              requestID=0;
        boolean                          debug=true;  
        InputStream                      in =null;
        OutputStream                     out=null;
        Server ()
        Server (Socket csocket)
            this.cSocket = csocket;
        /* start the server at specifed portNum */
        private void initialise ()
            try
                //start the server at serverPortNum
                sSock=new ServerSocket (serverPortNum);
            catch (IOException ex)
                ex.printStackTrace ();
            /* console output of status of server */
            if(debug==true)
                System.out.println ("Server waiting @ "+sSock);
        private void acceptRequest ()
            try
                this.cSocket=sSock.accept ();
                if(debug==true)
                    System.out.println ("client socket @ "+cSocket);
            catch (IOException ex)
                ex.printStackTrace ();
        private void readRequestID ()
            /*step 1: determine the type of server before threading
             *a request the the type of server got by the request ID
             * number */       
            try
                in        =cSocket.getInputStream ();
                requestID =in.read ();
                out       =cSocket.getOutputStream ();
                if(debug==true)
                    System.out.println ("accross the client:"+requestID);
            catch (IOException ex)
                ex.printStackTrace ();
        private void execThreadForRequest ()
            /*step 2: after requestID is received on the socket.
             *its time to decide the server to thread the control into.
            switch(requestID)
                case 1: //invoke the RegisterServer thread
                    new CodeServer.Core.RegistrationServer (this.cSocket).start ();
                    break;
                case 2: //invoke the ListingServer thread
                    break;
                case 3: //invoke the MessageTransferServer thread
                    break;
                case 4: //invoke the CallSetupServer thread
                    break;
                case 5: //invoke the DisconnectServer thread
                    break;
                case 6: //invoke the ChangeUserStatusServer thread
                    break;
        public void run ()
            // client processing code here==super class does nothing here
        public static void main (String args[]) throws Exception
            Server s=new Server ();
            s.initialise ();
            /* start indefinitely the main server thread */
            while (true)
               /* accept() blocks the server for a request
                  a new request is put into a thread for processing */
                s.acceptRequest (); //initialise the clientSocket
                s.readRequestID (); //get the actual requested service
                s.execThreadForRequest (); //start the actual server thread
    /**registration service class;
    *registers the IP address of the caller,callee and the status
    *adds the caller to the hash table and updates status
    class RegistrationServer extends Server
        Socket              cSocket;
        InetAddress         clientAddr;
        DataInputStream     inStream;
        DataOutputStream    outStream;
        //Socket s=new Socket()
        RegistrationServer (Socket cSocket)
            this.cSocket=cSocket;
            clientAddr =cSocket.getInetAddress ();
            try
                //init for reading status and custom message.
                inStream     =new DataInputStream (cSocket.getInputStream ());
                outStream    =new DataOutputStream (cSocket.getOutputStream ());
            catch (IOException ex)
                ex.printStackTrace ();
            if(CodeServer.ROO.DEBUG==true)
                System.out.println ("register server:"+cSocket
                                   +" host ip:"+clientAddr.getHostName ());
        public void run ()
            int    status=0;
            String custMesg=null;
            try
                /* read the custom message */
                if(inStream.available ()>0)
                    try
                        custMesg=inStream.readUTF ();
                        System.out.println (""+custMesg);
                    catch(EOFException e)
                        e.printStackTrace ();
                else
                    custMesg="";
            catch (IOException ex)
                ex.printStackTrace ();
                try
                           here is the problem, i found if i try reading accross the client             
                           i only receive a junk value 81 always */
                       outStream.write(1); //write success
                        outStream.flush();
                catch (IOException ex)
                    ex.printStackTrace ();
    }and with the client GUI :thanks for the help.please do find time to help me out with a suggestion or two on this code.

  • Adjusting Pool Threads

    Just to be sure... Adjusting the Pool Threads should increase the performance on the IIS server?
    And it's recommended to set it to twice the amount of devices.
    It is not there by default, so you have to create it. The default is 2 x MB of RAM eg. 4GB =
    PoolThreadLimit = 8000. So I should not change this setting, right? Unless I manage over 4000 devices?
    One more thing; from what I can see in the IIS docs the limit is 256, is this true? Because another site says
    "Range: 0 - 4,294,967,295 (unlimited)"
    So if the first one is true is should give nothing to set this reg key. A bit confused right now... ;-)
    I guess it's the last one that's the right one.
    So maybe this is the case: it's used as some kind of limit to make sure ZMM does not kill the IIS?
    Niels

    I think it's all pretty straighforward. You just need a request queue (probably a linked list) which contains Runnable objects. Then you fire up as many threads as you want, each thread waits for requests to become available and performs them. On 1.4 you have to make your own BlockingQueue but that's pretty easy. Use a LinkedList
    Your pooled thread just does something like
    public void run() {
        try {
          while(!Thread.currentThread().isIntererupted()) {
             Runnable request = null;
             synchronized requestQueue {
                   while(requestQueue.isEmpty())
                      requestQueue.wait();
                     request = requestQueue.removeFirst();
            request.run();
        } catch(InterruptedException e)  {
           // normal shutdown
      }(Though it might be wise to add some stuff to handle unchecked exceptions from the request).

  • I need help with socket connection pooling please

    I need a basic connection pooling system for the code below users sets number connections 5 etc.
    <main class>
    s = new ListService(ssock.accept(),serverDir); //give list to client
    Thread t = new Thread(s);
    t.start();
    <main class>
    class ListService implements Runnable
    Socket client;
    String serverDir;
    public ListService(Socket client,String serverDir)
    this.client = client;
    this.serverDir = serverDir;
    public void run()
    try
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
    // send something to client
    catch(Exception e)
    System.out.println(e);
    System.out.println("client disconnected\n");
    catch(Exception e){}
    Thank you so much

    My code already accepts multi clients I need pooling only 5 clients can be using the server at a time when one client disconnects that means another incoming client can enter the pool to use the server.
    I tried to do a counter so when a connection is made it increments and then if counter>=numOfClients
    set a variable to true or false and this is sent with the server setup so it determines if the server code is run or it just closes the connection but there is no way I can access the counter variable from within a runnable class thread when a client closes connection it should -1 from the variable
    thanks

  • How should I handle using this socket on multiple threads?

    Hey there, I'm writing a SocketServer app to handle client communications and I've run into something I'm not sure how to handle. Currently, I have the main method create the SocketServer and start new threads whenever a client connects and keeps a list of clients that need to be updated with some info ("Stuff") (Basically a list, which when changed, each update will be sent to all clients on the list to be informed of updates). Each thread that's created when a new client connects is passed the instance of the 'PoolHandler' class, which is supposed to handle updates to the "Stuff" and send updates to any clients that need them. Currently, when a client adds itself to the list of users that need to be informed of updates on "Stuff", the thread that handles that client adds the client name and socket to a hashmap in 'PoolHandler' and anytime the "Stuff" is updated, 'PoolHandler' accesses the passed socket and sends the updates. I realize I'm probably not doing a very good job of explaining this, so I'll show my code:
    public static void main(String[] args) throws IOException {
            final PoolHandler pool = new PoolHandler();
            ServerSocket serverSocket = null;
            while (listening) {
                new SNMultiServerThread(clients, pool, serverSocket.accept()).run();
    public class SNMultiServerThread implements Runnable {
        public void run() {
            try {
                out = new BufferedOutputStream(socket.getOutputStream());
                in = new BufferedInputStream(socket.getInputStream());
                try {
                    while ((read = in.read(input)) > 0) {
                        outputList = snp.process(input);
                        if (outputList != null && !outputList.isEmpty()) {
                            for (byte[] output : outputList) {
                                System.out.println("Transmitting: " +
                                        new String(output, 0, output.length));
                                synchronized(socket) {
                                    out.write(output);
                                    out.flush();
                } catch (SocketException e) {
    public class PoolHandler {
        public PoolHandler() {
        private void updateClients(String update, String game, String team) throws IOException {
            if (update.equalsIgnoreCase("add")) {
                if (game.equalsIgnoreCase(CS)) {
                    clientUpdateListDummy = clientUpdateListCs;
                } else {
                // The HashMap here is K=String, V=Socket
                for (Map.Entry<String, Socket> m : clientUpdateListDummy.entrySet()) {
                    try {
                        out = new BufferedOutputStream(m.getValue().getOutputStream());
                        out.write(snp.prepareOutput(ADD_TEAM_REPLY, team));
                        out.flush();
                    } catch (SocketException e) {
            } else if (update.equalsIgnoreCase("remove")) {
                if (game.equalsIgnoreCase(CS)) {
                    clientUpdateListDummy = clientUpdateListCs;
                } else {
                // The HashMap here is K=String, V=Socket
                for (Map.Entry<String, Socket> m : clientUpdateListDummy.entrySet()) {
                    try {
                        out = new BufferedOutputStream(m.getValue().getOutputStream());
                        synchronized(m.getValue()) { // synchronizing on the socket connected to the client, m.getValue()
                            out.write(snp.prepareOutput(REMOVE_TEAM_REPLY, team));
                            out.flush();
                    } catch (SocketException e) {
    }I attempted adding a synchronized block in the second for loop in PoolHandler, although i'm not sure if I need one at all or if that'll do the trick. The question, I guess, is should I be accessing the socket and then the outputstream for it from here (perhaps with the synchronized block that I added in the second for loop)? Or should I perhaps add a method in the Runnable class that transmits data via the socket and call that from PoolHandler? If I go with the second approach, can I simply pass the thread's name instead of the socket and use, say, m.getValue().transmitThisDataOverTheSocket(myData)? Thanks again, I hope this is clear. :)

    So I've got another question about my code: will the PoolHandler class be responsive if used in the main() thread or do I need to implement Runnable in it and create a new thread also? If so, how should I go about it since I don't want PoolHandler to do anything other than keep track of clients and a few other client-related variables? Here's my main():
    public static void main(String[] args) throws IOException {
            final PoolHandler pool = new PoolHandler();
            ServerSocket serverSocket = null;
            boolean listening = true;
            final int port = 4555;
            try {
                serverSocket = new ServerSocket(port);
            } catch (IOException e) {
                System.err.println("Couldn't listen on port: " + port);
                System.exit(-1);
            while (listening) {
                new SNThreadReader(pool, serverSocket.accept()).run();
            serverSocket.close();
        }

  • Socket programming and thread

    Hi all,
    I am getting problem while reading or writing to a port.
    we have two different thread for reading and writing, are they synchronize by itself or we have to make it explictly.
    the error i get are either of these two:
    1) java.io.EOFException
    2) java.net.SocketException: Broken pipe

    i am writing server and client which is thread based, i have implemented the biderectional ,first client writes to server. server reads from client first and then writes to client ,after server write client is not able to read data written by server. i am using the ObjectRead and Object Write methods of socket .
    At client when i read it gives the following error java.io.StreamCorruptedException
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at com.canarys.web.pushlet.newClient.run(Client.java:93)
    please help me out how to avoid this, the object i am using is serialised, if any of u need more clarification i will paste the code also
    any help regarding this will be appreciated

  • NIO issue - writing to sockets from 2 threads

    Hi All,
    I have some questions regarding a NIO-server i'm developing. I have read many posts relating this issue, but still...
    I have one thread that does the Selector.select() and read & write to the sockets
    I have another thread that uses the same Selector and changes the interestOp to OP_WRITE (then wakes up the Selector).
    I have a Connection (attachment) that i use to hold the inputBuffer and outputBuffer to handle remainings.
    I've read a post in which some ppl wrote the stages of using th OP_WRITE and it was suggested that only when i wanna write i'll add the OP_WRITE and exclude it in the isWritable() - so i'm doing that.
    My questions are:
    1. Is it safe to change the interestOp on a key from another thread?
    2. What happens if the select() is in process?
    3. Are there any other problems with my implementation?
    4. What other way i have to write to a socket from 2 different threads (withough putting a lock on the socket)?
    Thanks.

    Reset your thinking a bit. You should only register for OP_WRITE when you have just executed a 'short write', i.e. a return value > 0 but < the length you asked to write, and you should deregister OP_WRITE any time you execute a 'complete write', i.e. a write which writes everything you asked for. At all other times you should just write and handle your own syncrhonization. The reason is that socket channels are almost always writable except under the condition described so you will just be returning early from select() for nothing.

  • Sync 1 socket between 2 threads.

    consider this code:
    Socket sok = new Socket('192.158.9.42", 5432);
    ThreadClass_1 t1 = new ThreadClass_1(sok);
    t1.start();
    ThreadClass_2 t2 = new ThreadClass_2(sok);
    t2.start();
    t1 needs to download a large file. then t2 takes over
    for the remaining work. so... things are not going well.
    what is the best way to make sure t2 doesn't
    start using the Socket before t1 is finished
    with it?
    should this approach be working? i think it looks like a hack?
    i really don't know.
    private Object lock = new Object();
    Socket sok = new Socket('192.158.9.42", 5432);
    synchronized(lock) {
      ThreadClass_1 t1 = new ThreadClass_1(sok, lock);
      t1.start();
    synchronized(lock) {
      lock.wait();
      ThreadClass_2 t2 = new ThreadClass_2(sok);
      t2.start();
           private class ThreadClass_1 extends Thread {
               private Object lock;
               private Socket sok;
               ThreadClass_1(Socket sok, Object lock) {
                   this.sok = sok;
                   this.lock = lock;
                 public void run() {
                       // do my business with sok
                     this.lock.notify();
    should that work?
    is there anyway to do this without passing the lock down to
    ThreadClass_1 in the constructor?
    and, i'd rather not use some static boolean.
    thanks.

    i got it.
    this is what i need:
    Socket sok = new Socket('192.158.9.42", 5432);
    ThreadClass_1 t1 = new ThreadClass_1(sok);
    t1.start();
    t1.join()  // <----
    ThreadClass_2 t2 = new ThreadClass_2(sok);
    t2.start();and then seriously decrease the size of the write buffer.

  • A socket in several threads

    This is an academical question. I'm satudying Telecommunications and tomorrow I have an exam about Concurrent Programming.
    My questions is quite simple and you can ommit this introduction about what is the exercise if you prefer.
    We have seen some ways to pass messages between threads. Once we use an active monitor to take control over the mutex. In this case the active monitor consists of a simple Thread which answers proxys threads petitons for accesing to the mutex. To communicate with the Active Monitor we use s-pipes, which are just a pair of sockets connected where you send messages from one socket and read them from the other. For example we have an array of two sockets, connected: data[0] and data[1].
    The proxys thread have all of them the socket data[0] that they use for sending petitions in accesing mutex to the Active Monitor. Anything wrong till here?
    We use a BufferedReader (I think) for sending messages through the socket.
    Question: Can all these threads use this socket to send petitions without synchronizing it?

    That's not a problem. I didn't explain all the things which are involved in the program. The Control Thread doesn't answer through the same s-pipe.
    So if T1 and T2 ask for acces to mutex, they wait until they recieve a responsen in an another s-pipe only dedicated for each of them. The s-pipe I called data[0] and data[1] is used just for sending requests and nothing else.
    So there are:
    - A pair of sockets for sending petitions to Control Thread, they are used only in one way. In this case data[0] is the socket in the proxys threads (T1, T2, ....) and data[1] is the socket in the Control Thread.
    - A pair of sockets for each proxy thread, for answering petitions of all the Proxy Threads. For example. If we have 3 proxy threads: T1, T2 and T3. There are then: RecieveAskT1[1] which is in T1; RecieveAskT1[0] which is in Control Thread.
    RecieveAskT2[1] which is in T1; RecieveAskT2[0] which is in Control Thread.
    RecieveAskT3[1] which is in T1; RecieveAskT3[0] which is in Control Thread.
    So the problem is with the socket data[0] which is used for T1, T2,...
    What is important for me is: if some of the methods which are involved in sending "things" through a socket are synchronized? Otherwise I cannot understand how my professer uses data[0] without protecting it against the scheduler.
    Previous thanks for you future answer!

  • Properly closing socket and killing thread in cmd window

    Hey all,
    I'm creating my socket connection in a program that i am running in a cmd window. For what i need in my prog, i have a loop that tries to connect every 5 seconds, and even after that, I need to continue looping to check and try to connect.
    The only way i can end the program is to cntrl-c or X out of the program. What i need to know is there a way to properly clean up the thread and close the socket w/o any memory leak issues?
    Thanks

    What i need to know is there a
    way to properly clean up the thread and close the
    socket w/o any memory leak issues?All modern popular use OSes clean sockets, threads and memory (normal) when the application exits for any reason at all.

  • Pooling threads

    I know the Doug Lea util.concurrent package, and there is a thread pool implementation. I also know some apps that use thread pools.
    But the Thread class doesn't allow running more than one instance of a runnable... and it's not possible to change the runnable instance in a Thread once it'was created. I think you can run it twice (after it stopped, but never tried).
    So how do you implement a thread pool in java? As far as I know, the Doug Lea's pool creates a new thread every time, it only limits the maximun amount of threads, am I right?

    The trick is to wrap Runnable with another inner Runnable.
    Basically:
    You have a queue, and bunch of threads whose runnables have settable inner runnables.
    1. While a Thread's Runnable's inner runnable is null it waits...
    2. You put a runnable on the queue.
    3. It waits for the next available thread, removes it from the pool, sets it's runnables inner runnable to the one you actually want to run.
    4. Stuff happens...
    5. When the runnable is finished executing your runnable it adds the thread back to the pool.

  • Thread Pool in JRT

    Hi All,
    1) the first question is what is the recommended way to allocate thread poll in rt system??
    2) what is the best way to do:
    -if my mission take a long time can i just suspend the thread and than resume it again (is it possible at all??)
    or the other option is to return it to the pool and get it again and again.
    im asking the second question from the view of performance and low latency .
    i assumed that each time i return the thread to the pool and than active it again it will "cost" cpu time.
    hope my question is clear enough.
    TIA
    Gabi

    Hi Gabi,
    I'm not completely clear on your questions. You can create a thread pool in a RT system the same basic way as in non-RT but you need to deal with priorities correctly. One way to do this would be to have the pool threads run at maximum priority normally and then drop to the actual priority of a submitted work task. Another model is to split the pool into groups based on priority, so effectively there is a work queue per priority-level and a group of threads to service each pool. This second model is used in the Real-time CORBA "lanes" approach. Designing an effective thread pool is a non-trivial task (take a look at the java.util.concurrent Thread PoolExecutor) and dealing with RT priorities and RT latency issues makes it even more complex.
    Alternatively rather than use an explicit thread pool consider whether you can convert the design to one using AsyncEvents and AsyncEventHandlers.
    Question 2 I don't really understand. Pool threads typically block on a queue waiting for work tasks to appear. But you can also have a non-terminating task that effectively picks up its own work from elsewhere - eg a task that reads from a socket to get the next "job" to process. Any interaction between threads is going to cost CPU time, whether a pool is involved or not, but yes there will be overhead associated with a pool, just as there is starting and terminating a thread, or performing any kind of thread coordination/synchronization.
    Regards,
    David Holmes

  • Using Threads And Sockets

    Hello,
    I want to create a program that can send 2 or more files through the socket to the same client at the same time. Is it possible? I am trying to use threads to do this but I am not sure what to do in those threads. Should I send the socket to the thread class and create BufferedReader and DataOutputStream again in the thread?
    Also should I create threads in the client-side?
    Thanks
    Edited by: bcaputcu on May 18, 2010 2:19 AM

    bcaputcu wrote:
    Hello,
    I want to create a program that can send 2 or more files through the socket to the same client at the same time. Is it possible?No. At least not in the way you're thinking.
    I am trying to use threads to do this but I am not sure what to do in those threads. Should I send the socket to the thread class and create BufferedReader and DataOutputStream again in the thread?No, because you can't do that. The socket won't create multiple streams for your threads.
    Also should I create threads in the client-side?No.
    You need to send the files one at a time. While you could basically send the data interleaved, it would still only involve only one thread, one socket and one set of streams. And it would be a silly thing to do.

Maybe you are looking for

  • Upgrade to iTunes 8 and now can't play movies

    I updated from iTunes 7. something to 8 and can no longer play DVD's using PowerDVD or WMP. I can't even see the disk drive under My Computer. I did a system restore on my HP laptop and could play movies again but when I tried to open iTunes the the

  • After UD stock is in Quality stock

    Hi All,    I am getting a problem with the Inspection lot, After doing UD for the inspection lot , System status is showing   UD   ICCO SPCO STUP HUM means stock posting is completed but actually the stock is not moving from quality stock to Unrestri

  • QR Code Reader

    Is it possible to download a QR code reader for the iPhone?

  • Jco.server.max_startup_delay

    SAP Note 730870 say: Q 25: A RFC sender channel is registered at a SAP Gateway which is shutdown. Does the RFC sender channel automatically reconnect to the SAP Gateway after it is available again? A: The SAP Gateway is shutdown due to e.g. offline b

  • How do I resolve X11 ""RANDR" missing on display "localhost:10.0"" for OX 10.6.7 error?

    Typically this error ( "RANDR" missing on display "localhost:10.0") doesn't cause any problems but it is annoying. Is there a solution for this?