Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class Foo {
  2. private RedisConnection _connection;
  3.  
  4. public void doSomething() {
  5. // get connection from existing pool
  6. // store ref to connection in object state
  7. _connection = RedisConnectionPool.get().checkout();
  8. try {
  9. // write or read data from Redis here
  10. }
  11. finally {
  12. // release connection back to pool
  13. // retain connection ref in object state (whoops!)
  14. RedisConnectionPool.get().checkin(_connection);
  15. }
  16. }
  17.  
  18. public void cleanUp() {
  19. // close connection when cleaning up object instance
  20. // even though the connection is owned by pool (double whoops!)
  21. if (_connection) {
  22. _connection.close();
  23. _connection = null;
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement