With JAVA through API connection cannot keep online state

Everybody is good, my English is not very good, do not know if you can see, I hope you can help me
I wrote a program using JAVA, it connected through the API interface routeros,
But each to execute a command, to visit and exit time,
I put the connection into a class, and then call the class, not every time I landed, but ten seconds no operation will quit, cannot remain online,
How can I keep it online?