开发者

How much timeout to use in isValid()?

In the method from Connection, how much timeout should I give it? :S I have no idea what a normal timeout would be, how much time should it take? :)

I dont want isValid() to ret开发者_StackOverflow社区urn false if it could return true if it had gotten more time, but also I don't want it to slow down the whole program and give me "freezes".

If I set 0, does that mean I don't care for any timeout, it will try for as long as it needs to?

Thanks!


This depends on a lot of things. Generally, I'd assume that the time that isValid takes is about the same time that a simple query would take. For that reason, I would use the maximum acceptable time for the user.

E.g. if you think that users of your (say) web application will wait at most 5 seconds for a response before giving up, you might want to use that value for isValid. Because it makes no sense to declare the connection valid if it takes, say, 50 seconds to reach the database.


I have no idea what a normal timeout would be, how much time should it take?

Then put the timeout into the program configuration (whatever this is). Maybe log the events when timeout occur and get some experience over time what a normal timeout is.

... but also I don't want it to slow down the whole program and give me "freezes"

Is this an interactive program for end-users, then think how much time she will wait without to get nervous. For me 2-3 seconds is still ok, dependingwhat the program is doing for me.

Is this a background server program think about what can happen that the connection get delayed (reconnect network, etc). A background program can wait longer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜