In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "java collection class deep example usage", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "java collection class deep example usage" bar!
When doing cloud computing xenserverAPI to connect to xenserver and close xenserver, because there are scheduled tasks refreshing every minute, xenserver will often be connected and closed when accessing data in scheduled tasks, resulting in xenserver connection blocking, so the connection is put into the queue to connect and disconnect.
/ * xenserverAPI call interface * @ author hanxuan * @ version 2016-12-14 * / public class XenPool {private static Logger logger = Logger.getLogger (XenPool.class); private static final int XENSERVER_POOL_CAPACITY=20;private static Map pool = new ConcurrentHashMap; public XenPool () {} public synchronized static Connection getConnect (XenServer xenServer) {URL url = null;try {url = new URL (xenServer.Hostname) } catch (MalformedURLException e) {e.printStackTrace (); return null;} String host=url.getHost (); Queue queue = pool.get (host); Connection connection = null;if (queue! = null) {Object conn = queue.poll (); if (conn! = null) {connection = (Connection) conn }} if (connection==null) {try {connection= new Connection (new URL (xenServer.Hostname), XenServer.REPLY_WAIT, XenServer.CONNECT_WAIT);} catch (MalformedURLException e) {logger.error ("xenserver [" + xenServer.Hostname + "] connection is abnormal!", e) } try {Session.loginWithPassword (connection, xenServer.Username, SystemService.decryptPassword (xenServer.Password), APIVersion.latest (). ToString ());} catch (Types.XenAPIException e) {logger.error ("xenserver [" + xenServer.Hostname + "] XenAPIException exception!", e);} catch (XmlRpcException e) {logger.error ("xenserver [" + xenServer.Hostname + "] XmlRpcException exception!", e) }} return connection;} public static void disconnect (Connection connection) {String host= null;try {host= connection.getConfig (). GetServerURL (). GetHost ();} catch (Exception e) {e.printStackTrace (); return;} Queue queue= pool.get (host); if (queue==null) {queue= new ArrayBlockingQueue (XENSERVER_POOL_CAPACITY) Pool.put (host, queue);} boolean flag=queue.offer (connection); if (! flag) {/ / put in queue try {Session.logout (connection) when the connection is not in use;} catch (Types.XenAPIException e) {logger.error ("xenserver [" + host + "] release exception!", e) } catch (XmlRpcException e) {logger.error ("xenserver [" + host + "] release exception!", e) Thank you for your reading. The above is the content of "java collection class deep instance usage". After the study of this article, I believe you have a deeper understanding of the problem of java collection class deep instance usage, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.