Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking integrity of Connection  RSS feed

 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How can we check integrity of connection.
Before performing any operation

Regards
Shrikant
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could perform some kind of dummy operation that is quick to execute and doesn't alter any data. But that's not guarantee that the connection won't fail during the subsequent "real" operation.

What problems do you see in just performing the operation, and then handling any exceptions if they occur?
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have written one socket server which is listening from 2-3 client.
and Server socket is reading in while loop, it is reading lot's of information and after that I am dumping that information into database.
But before reading I checked integrity of connection using con.isReadOnly();(dummy operation) .This is required because if I have no db connetion avaible . I am closing socket server thus at closing socket client so that all infromation get logged in file at socket client side.
is this approch Correct? and will con.isReadOnly() method work.?
Thanks
Shrikant
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your question is whether conn.isReadOnly() will work or not then its yes, it will work.
I have a few comments on your design otherwise:

What if after reading all data you find out that the db connection is stale?

Moreover, reading from the socket and writing to DB in the same thread will hit the socket reading capacity alot i.e. after reading the data from the client, you will waste the worker's time in updating DB. Instead, either you can give this task to another thread or write it on a file to be pushed into DB by another process at a later point of time.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!