I am using contentDB API to integrate my system with content DB. In my application I have quite few methods that make some operations inside content DB. Everything works fine but slow :(. The problem is that in each of my methods I do call a method connect
FileManager fileManager = session.getFileManager();
CategoryManager categoryManager = session.getCategoryManager();
Method that return session:
private ManagersFactory connect()
trace.debug("Logging to CDB Storage : "+ CDBUrl);
FdkCredential credential = new SimpleFdkCredential(username, password);
session = ManagersFactory.login(credential, CDBUrl);
Login method (session = ManagersFactory.login(credential, CDBUrl)) takes a lot of time. How can I refactor my code to make it work quickly? My application is mulithreded. Is thare a bulid in mechanism to manage sessions? Or is it possible to create a special user that will not need a lot of time to authenticate in content DB?
Edited by: user8726358 on 2010-08-31 08:01
Edited by: user8726358 on 2010-08-31 08:04
Edited by: user8726358 on 2010-08-31 08:06
first of all, I don't see a disconnect in your code. This means that all connections you are establish are never closed normally, and will stay open until they expire and time out. This is bad coding style.
Second, why don't you implement your own connection pool? As more important if your application is multi-threaded. If you don't do that in your scenario, you will quickly hit the Maximum_Sessions_Per_User limit, because most of your sessions will be unused until they time out. This implies even more problems with memory management and garbage collection.
The are tons of examples and tutorials available on the Internet, how to implement a simple connection pool. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid.
Hope that helps,
Thanks for response. I have a disconnect method in my code ;). Above was just an example . I have implemented connection pool as you adviced it works much faster when pool is already created but Firrst creation of session takes a lot of time I thought that tere is some bulit in machansm that works more quickly than calling ManagersFactory.login(credential, CDBUrl). Pooling solves my problems for now :) thanks.
what exactly is "a lot of time" for you in this context? Is this around 3 seconds? Depending on your hardware and configuration, this could be normal. You could pre-create the sessions during startup of your application to avoid waiting time when the session is requested. This can be done in the background and would have no delay impact on your code.