數據庫連接池的設計思路及java實現

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

connectionPool.DBConnectionManager

[java]?view plain?copy

  1. package?connectionPool;??
  2. ??
  3. import?java.sql.Connection;??
  4. import?java.sql.Driver;??
  5. import?java.sql.DriverManager;??
  6. import?java.sql.SQLException;??
  7. import?java.util.ArrayList;??
  8. import?java.util.Enumeration;??
  9. import?java.util.HashSet;??
  10. import?java.util.Hashtable;??
  11. import?java.util.List;??
  12. import?java.util.Map;??
  13. import?java.util.Map.Entry;??
  14. import?java.util.Set;??
  15. ??
  16. import?connectionPool.util.Logger;??
  17. import?connectionPool.util.PropertiesMgr;??
  18. ??
  19. /**?
  20. ?*?連接池的設計思路?
  21. ?*?1、?
  22. ?*?初始化固定數目的連接(空閑連接與活躍連接在同一池中),建立連接的代理類,添加busy與startTime屬性以便分發與回收連接?
  23. ?*?另建立守護線程回收失效連接?
  24. ?*?2、?
  25. ?*?維護一空閑連接池,初始為空,需要連接時建立,用完的連接回收進入空閑連接池;?
  26. ?*?后續所需連接從空閑連接池獲取;activeNum記錄活躍連接數目;?
  27. ?*?當空閑連接池為空且活躍連接數達到上限時,請求等待,超時即獲取連接失敗,超時前有連接被釋放方可獲得連接?
  28. ?*?第二個設計巧妙優勢明顯,采用第二種方式?
  29. ?*??
  30. ?*?數據庫連接管理類,單例模式?
  31. ?*?可以管理加載多個數據庫驅動,維護多個數據庫連接池?
  32. ?*?@author?shijin?
  33. ?*?
  34. ?*/??
  35. public?class?DBConnectionManager?{??
  36. ??????
  37. ????private?static?DBConnectionManager?dbm?=?null;??
  38. ??????
  39. ????//單例模式里的成員變量都相當于是static了???
  40. ????/**?
  41. ?????*?客戶數目?
  42. ?????*/??
  43. ????private?static?int?clients?=?0;??
  44. ????/**?
  45. ?????*?加載的驅動器集合?
  46. ?????*/??
  47. ????private?Set<Driver>?drivers?=?new?HashSet<Driver>();??
  48. ????/**?
  49. ?????*?數據庫連接池字典?
  50. ?????*/??
  51. ????private?Hashtable<String,DBConnectionPool>?pools?=?new?Hashtable<String,DBConnectionPool>();??
  52. ??????
  53. ????private?final?Logger?log?=?Logger.getInstance(DBConnectionPool.class);??
  54. ??????
  55. ????private?DBConnectionManager()?{??
  56. ????????loadDrivers();??
  57. ????????createPools();??
  58. ????}??
  59. ??
  60. ????/**?
  61. ?????*?裝載和注冊所有的JDBC驅動程序?
  62. ?????*/??
  63. ????private?void?loadDrivers()?{??
  64. ????????String?str_drivers?=?PropertiesMgr.getProperty("driver");??
  65. ????????for(String?str_driver:str_drivers.split("\\s"))?{??
  66. ????????????Driver?driver?=?null;??
  67. ????????????try?{??
  68. ????????????????driver?=?(Driver)Class.forName(str_driver).newInstance();??
  69. ????????????????DriverManager.registerDriver(driver);??
  70. ????????????????log.info("成功加載JDBC驅動:"?+?str_driver);??
  71. ????????????}?catch?(InstantiationException?e)?{??
  72. ????????????????log.error("加載JDBC驅動"?+?str_driver?+?"時初始化異常,請檢查配置文件");??
  73. ????????????}?catch?(IllegalAccessException?e)?{??
  74. ????????????????log.info("加載JDBC驅動"?+?str_driver?+?"時非法訪問,請檢查配置文件");??
  75. ????????????}?catch?(ClassNotFoundException?e)?{??
  76. ????????????????log.info("未找到JDBC驅動"?+?str_driver?+?"請引入相關包");??
  77. ????????????}?catch?(SQLException?e)?{??
  78. ????????????????log.info("加載JDBC驅動"?+?str_driver?+?"失敗,請檢查引入包的正確性");??
  79. ????????????}??
  80. ????????????drivers.add(driver);??
  81. ????????}??
  82. ????}??
  83. ??
  84. ????/**?
  85. ?????*?根據配置文件創建數據庫連接池?
  86. ?????*/??
  87. ????private?void?createPools()?{??
  88. ????????Enumeration<?>?elements?=?PropertiesMgr.propertiesNames();??
  89. ????????while(elements.hasMoreElements())?{??
  90. ????????????String?element?=?(String)elements.nextElement();??
  91. ????????????if(element.endsWith(".url"))?{??
  92. ????????????????String?poolName?=?element.substring(0,?element.lastIndexOf("."));??
  93. ????????????????String?url?=?PropertiesMgr.getProperty(poolName?+?".url");??
  94. ????????????????if(url?==?null)?{??
  95. ????????????????????log.error("無法連接到數據庫"?+?poolName?+?"請檢查配置文件連接字符串");??
  96. ????????????????????continue;??
  97. ????????????????}??
  98. ????????????????String?user?=?PropertiesMgr.getProperty(poolName?+?".user");??
  99. ????????????????String?pwd?=?PropertiesMgr.getProperty(poolName?+?".password");??
  100. ????????????????String?str_max?=?PropertiesMgr.getProperty(poolName?+?".maxconn",?"0");??
  101. ????????????????int?maxConn?=?0;??
  102. ????????????????try{??
  103. ????????????????????maxConn?=?Integer.parseInt(str_max);??
  104. ????????????????}catch(NumberFormatException?e)?{??
  105. ????????????????????log.error("數據庫"?+?poolName?+?"最大連接數設置錯誤,默認設為20");??
  106. ????????????????????maxConn?=?20;??
  107. ????????????????}?????????????????
  108. ????????????????DBConnectionPool?pool?=?new?DBConnectionPool(maxConn,url,poolName,user,pwd);??
  109. ????????????????pools.put(poolName,?pool);??
  110. ????????????????log.info("成功創建數據庫連接池"?+?poolName);??
  111. ????????????}??
  112. ????????}??
  113. ????}??
  114. ??
  115. ????/**?
  116. ?????*?獲得單例?
  117. ?????*?@return?DBConnectionManager單例?
  118. ?????*/??
  119. ????public?synchronized?static?DBConnectionManager?getInstance()?{??
  120. ????????if(dbm?==?null)?{??
  121. ????????????dbm?=?new?DBConnectionManager();??
  122. ????????}??
  123. ????????clients++;??
  124. ????????return?dbm;??
  125. ????}??
  126. ??
  127. ????/**?
  128. ?????*?從指定連接池中獲取可用連接,無等待?
  129. ?????*?@param?poolName??要獲取連接的連接池名稱?
  130. ?????*?@return??連接池中的一個可用連接或null?
  131. ?????*/??
  132. ????public?Connection?getConnection(String?poolName)?{??
  133. ????????DBConnectionPool?pool?=?(DBConnectionPool)pools.get(poolName);??
  134. ????????return?pool.getConnection();??
  135. ????}??
  136. ??????
  137. ????/**?
  138. ?????*?從指定的連接池獲取可用連接,有等待超時?
  139. ?????*?@param?poolName??要獲取連接的連接池名稱?
  140. ?????*?@param?timeout???獲取可用連接的超時時間,單位為秒?
  141. ?????*?@return??????????連接池中的一個可用連接或null?
  142. ?????*/??
  143. ????public?Connection?getConnection(String?poolName,long?timeout)?{??
  144. ????????DBConnectionPool??pool?=?(DBConnectionPool)pools.get(poolName);??
  145. ????????return?pool.getConnection(timeout);??
  146. ????}??
  147. ??????
  148. ????/**?
  149. ?????*?回收指定連接池的連接?
  150. ?????*?@param?poolName??連接池名稱?
  151. ?????*?@param?conn??????要回收的連接?
  152. ?????*/??
  153. ????public?void?freeConnection(String?poolName,Connection?conn)?{??
  154. ????????DBConnectionPool?pool?=?(DBConnectionPool)pools.get(poolName);??
  155. ????????if(pool?!=?null)?{??
  156. ????????????pool.freeConnection(conn);??
  157. ????????}??
  158. ????????log.error("找不到連接池,無法回收,請檢查參數");??
  159. ????}??
  160. ??????
  161. ????/**?
  162. ?????*?關閉所有連接,撤銷驅動器的注冊?
  163. ?????*/??
  164. ????public?synchronized?void?release()?{??
  165. ????????//所有客戶連接都關閉時才真正關閉連接撤銷注冊??
  166. ????????if(clients--?!=?0)?{??
  167. ????????????return;??
  168. ????????}??
  169. ????????for(Map.Entry<String,DBConnectionPool>?poolEntry:pools.entrySet())?{??
  170. ????????????DBConnectionPool?pool?=?poolEntry.getValue();??
  171. ????????????pool.releaseAll();??
  172. ????????}??
  173. ????????log.info("已經關閉所有連接");??
  174. ????????for(Driver?driver:drivers)?{??
  175. ????????????try?{??
  176. ????????????????DriverManager.deregisterDriver(driver);??
  177. ????????????????log.info("撤銷JDBC驅動器"?+?driver.getClass().getName()?+?"的注冊");??
  178. ????????????}?catch?(SQLException?e)?{??
  179. ????????????????log.error("撤銷JDBC驅動器"?+?driver.getClass().getName()?+?"的注冊異常");??
  180. ????????????}??
  181. ????????}??
  182. ????????log.info("驅動器撤銷完成");??
  183. ????}??
  184. ??????
  185. ????/**?
  186. ?????*?此內部類定義了一個連接池.?
  187. ?????*?它能夠獲取數據庫連接,直到預定的最?大連接數為止?
  188. ?????*?在返回連接給客戶程序之前,它能夠驗證連接的有效性?
  189. ?????*?@author?shijin?
  190. ?????*/??
  191. ????private?class?DBConnectionPool?{??
  192. ????????private?int?activeNum?=?0;??
  193. ????????private?int?maxConn?=?0;??
  194. ????????private?String?url?=?null;??
  195. ????????private?String?poolName?=?null;??
  196. ????????private?String?user?=?null;??
  197. ????????private?String?pwd?=?null;??
  198. ????????private?List<Connection>?freeConnections?=?new?ArrayList<Connection>();??
  199. ??????????
  200. ????????/**?
  201. ?????????*??
  202. ?????????*?@param?maxConn???設定的連接池允許的最大連接數?
  203. ?????????*?@param?url???????數據庫連接url?
  204. ?????????*?@param?poolName??連接池名稱?
  205. ?????????*?@param?user??????數據庫用戶名,或null?
  206. ?????????*?@param?pwd???????數據庫用戶密碼,或null?
  207. ?????????*/??
  208. ????????public?DBConnectionPool(int?maxConn,?String?url,?String?poolName,??
  209. ????????????????String?user,?String?pwd)?{??
  210. ????????????super();??
  211. ????????????this.maxConn?=?maxConn;??
  212. ????????????this.url?=?url;??
  213. ????????????this.poolName?=?poolName;??
  214. ????????????this.user?=?user;??
  215. ????????????this.pwd?=?pwd;??
  216. ????????}??
  217. ??????????
  218. ????????/**?
  219. ?????????*?獲得一個可用連接,不保證任何情況都能返回一個連接(比如超過最大連接數的時候返回null)?
  220. ?????????*?1、若空閑連接池不為空,從空閑連接池取出一個連接后檢查有效性,正常則返回,失效則重新獲取連接?
  221. ?????????*?2、若空閑連接池為空且未超過最大連接數限制,新建一個連接并返回?
  222. ?????????*?3、空閑連接數為空且超過最大連接數限制,返回null?
  223. ?????????*?@return??獲得的可用連接?
  224. ?????????*/??
  225. ????????public?synchronized?Connection?getConnection()?{??
  226. ????????????Connection?conn?=?null;??
  227. ????????????//空閑連接池中有空閑連接,直接取??
  228. ????????????if(freeConnections.size()?>?0)?{??
  229. ????????????????//從空閑連接池中取出一個連接??
  230. ????????????????conn?=?freeConnections.get(0);??
  231. ????????????????freeConnections.remove(0);??
  232. ????????????????//檢測連接有效性??
  233. ????????????????try{??
  234. ????????????????????if(conn.isClosed())?{??
  235. ????????????????????????//由于已經從空閑連接池取出,所以不使用無效連接其就無法重新進入??
  236. ????????????????????????//空閑連接池,意味著其已經被刪除了,記入日志即可??
  237. ????????????????????????log.info("從連接池"?+?poolName?+?"中取出的連接已關閉,重新獲取連接");??
  238. ????????????????????????//繼續從連接池嘗試獲取連接??
  239. ????????????????????????conn?=?getConnection();??
  240. ????????????????????}??
  241. ????????????????}catch(SQLException?e)?{??
  242. ????????????????????log.info("從連接池"?+?poolName?+?"中取出的發生服務器訪問錯誤,重新獲取連接");??
  243. ????????????????????conn?=?getConnection();??
  244. ????????????????}??
  245. ????????????}?else?if(activeNum?<?maxConn)?{??
  246. ????????????????conn?=?newConnection();??
  247. ????????????}?else?{??
  248. ????????????????//未獲得連接??
  249. ????????????}??
  250. ????????????if(conn?!=?null)?{??
  251. ????????????????activeNum++;??
  252. ????????????}??
  253. ????????????return?conn;??
  254. ????????}??
  255. ??????????
  256. ????????/**?
  257. ?????????*?當無空閑連接而又未達到最大連接數限制時創建新的連接?
  258. ?????????*?@return??新創建的連接?
  259. ?????????*/??
  260. ????????private?Connection?newConnection()?{??
  261. ????????????Connection?conn?=?null;??
  262. ????????????try{??
  263. ????????????????if(user?==?null)?{??
  264. ????????????????????conn?=?DriverManager.getConnection(url);??
  265. ????????????????}?else?{??
  266. ????????????????????conn?=?DriverManager.getConnection(url,?user,?pwd);??
  267. ????????????????}??
  268. ????????????????log.info("與數據庫"?+?poolName?+?"創建一個新連接");??
  269. ????????????}catch(SQLException?e)?{??
  270. ????????????????log.error("無法根據\""?+?url?+?"\"與數據庫"?+?poolName?+?"建立新連接");??
  271. ????????????}??
  272. ????????????return?conn;??
  273. ????????}??
  274. ??????????
  275. ????????/**?
  276. ?????????*?獲得一個可用連接,超過最大連接數時線程等待,直到有有連接釋放時返回一個可用連接或者超時返回null?
  277. ?????????*?@param?timeout?等待連接的超時時間,單位為秒?
  278. ?????????*?@return?
  279. ?????????*/??
  280. ????????public?synchronized?Connection?getConnection(long?timeout)?{??
  281. ????????????Connection?conn?=?null;??
  282. ????????????long?startTime?=?System.currentTimeMillis();??
  283. ????????????while((conn?=?getConnection())?==?null)?{??
  284. ????????????????try{??
  285. ????????????????????//被notify(),notifyALL()喚醒或者超時自動蘇醒??
  286. ????????????????????wait(timeout);??
  287. ????????????????}catch(InterruptedException?e)?{??
  288. ????????????????????log.error("等待連接的線程被意外打斷");??
  289. ????????????????}??
  290. ????????????????//若線程在超時前被喚醒,則不會返回null,繼續循環嘗試獲取連接??
  291. ????????????????if(System.currentTimeMillis()?-?startTime?>?timeout*1000000)??
  292. ????????????????????return?null;??
  293. ????????????}??
  294. ????????????return?conn;??
  295. ????????}??
  296. ??????????
  297. ????????/**?
  298. ?????????*?將釋放的空閑連接加入空閑連接池,活躍連接數減一并激活等待連接的線程?
  299. ?????????*?@param?conn??釋放的連接?
  300. ?????????*/??
  301. ????????public?synchronized?void?freeConnection(Connection?conn)?{??
  302. ????????????freeConnections.add(conn);??
  303. ????????????activeNum--;??
  304. ????????????notifyAll();//通知正在由于達到最大連接數限制而wait的線程獲取連接??
  305. ????????}??
  306. ??????????
  307. ????????/**?
  308. ?????????*?關閉空閑連接池中的所有連接?
  309. ?????????*/??
  310. ????????public?synchronized?void?releaseAll()?{??
  311. ????????????for(Connection?conn:freeConnections)?{??
  312. ????????????????try{??
  313. ????????????????????conn.close();??
  314. ????????????????????log.info("關閉空閑連接池"?+?poolName?+?"中的一個連接");??
  315. ????????????????}catch(SQLException?e)?{??
  316. ????????????????????log.error("關閉空閑連接池"?+?poolName?+?"中的連接失敗");??
  317. ????????????????}??
  318. ????????????}??
  319. ????????????freeConnections.clear();??
  320. ????????}??
  321. ????}??
  322. }??

connectionpool.util.Logger

[java]?view plain?copy

  1. package?connectionPool.util;??
  2. ??
  3. import?java.io.FileWriter;??
  4. import?java.io.IOException;??
  5. import?java.io.PrintWriter;??
  6. import?java.util.Date;??
  7. ??
  8. /**?
  9. ?*?日志文件創建維護類,單例模式?
  10. ?*?@author?shijin?
  11. ?*?
  12. ?*/??
  13. public?class?Logger?{??
  14. ??????
  15. ????private?static?Logger?logger=?null;??
  16. ????private?PrintWriter?log?=?null;??
  17. ????private?static?int?level?=?0;??
  18. ????private?Class<?>?c?=?null;??
  19. ????private?static?final?int?DEBUGLEVEL?=?1;??
  20. ????private?static?final?int?INFOLEVEL?=?2;??
  21. ????private?static?final?int?ERRORLEVEL?=?3;??
  22. ??????
  23. ????private?Logger(Class<?>?c)?{??
  24. ????????String?logFileName?=?PropertiesMgr.getProperty("logfile","DBlog.txt");??
  25. ????????String?str_level?=?PropertiesMgr.getProperty("loglevel",?"3");??
  26. ????????this.c?=?c;??
  27. ????????level?=?Integer.parseInt(str_level);??
  28. ????????try?{??
  29. ????????????log?=?new?PrintWriter(new?FileWriter(logFileName),true);??
  30. ????????}?catch?(IOException?e)?{??
  31. ????????????System.err.println("無法打開日志文件"?+?logFileName);??
  32. ????????????log?=?new?PrintWriter(System.err);??
  33. ????????}??
  34. ????}??
  35. ??????
  36. ????public?synchronized?static?Logger?getInstance(Class<?>?c)?{??
  37. ????????if(logger?==?null)?{??
  38. ????????????logger?=?new?Logger(c);??
  39. ????????}??
  40. ????????return?logger;??
  41. ????}??
  42. ??????
  43. ??????
  44. ????public?void?debug(String?msg)?{??
  45. ????????if(level?>?DEBUGLEVEL)?{??
  46. ????????????msg?=?"DEBUG:"?+?new?Date()?+?"-"?+?msg;??
  47. ????????????System.out.println(msg);??
  48. ????????????log.println(msg);??
  49. ????????}??
  50. ??????????????
  51. ????}??
  52. ??????
  53. ????public?void?info(String?msg)?{??
  54. ????????if(level?>?INFOLEVEL)?{??
  55. ????????????msg?=?"INFO:"?+?new?Date()?+?"-"?+?msg;??
  56. ????????????System.out.println(msg);??
  57. ????????????log.println(msg);??
  58. ????????}??
  59. ??????????????
  60. ????}??
  61. ??????
  62. ????public?void?error(String?msg)?{??
  63. ????????if(level?>?ERRORLEVEL)?{??
  64. ????????????msg?=?"ERROR:"?+?new?Date()?+?"-"?+?c?+?"-"?+?msg;??
  65. ????????????System.out.println(msg);??
  66. ????????????log.println(msg);??
  67. ????????}??
  68. ????}??
  69. }??

connection.util.PropertiesMgr

[java]?view plain?copy

  1. package?connectionPool.util;??
  2. ??
  3. import?java.io.File;??
  4. import?java.io.IOException;??
  5. import?java.util.Enumeration;??
  6. import?java.util.Properties;??
  7. /**?
  8. ?*?屬性文件加載管理類,單例模式?
  9. ?*?@author?shijin?
  10. ?*?
  11. ?*/??
  12. public?class?PropertiesMgr?{??
  13. ????private?static?Properties?pro?=?new?Properties();??
  14. ????private?PropertiesMgr(){}??
  15. ????static?{??
  16. ????????try?{??
  17. ????????????pro.load(PropertiesMgr.class.getClassLoader().getResourceAsStream("config"?+?File.separator?+?"DB.properties"));??
  18. ????????}?catch?(IOException?e)?{??
  19. ????????????e.printStackTrace();??
  20. ????????}??
  21. ????}??
  22. ??????
  23. ????public?static?String?getProperty(String?key)?{??
  24. ????????return?pro.getProperty(key);??
  25. ????}??
  26. ??????
  27. ????public?static?String?getProperty(String?key,String?defaultValue)?{??
  28. ????????//找不到key用defaultValue,而不是說后面為空字符串采用defaultValue??
  29. ????????return?pro.getProperty(key,?defaultValue);??
  30. ????}??
  31. ??????
  32. ????public?static?Enumeration<?>?propertiesNames()?{??
  33. ????????return?pro.propertyNames();??
  34. ????}??
  35. }??

DB.properties

[plain]?view plain?copy

  1. driver=com.mysql.jdbc.Driver??
  2. ??
  3. mysql.url=jdbc:mysql://127.0.0.1/caiwu?useUnicode=true&characterEncoding=gb2312??
  4. ??
  5. mysql.user=root??
  6. ??
  7. mysql.password=123??
  8. ??
  9. mysql.maxconn=1000??
  10. ??
  11. #\u65E5\u5FD7\u6587\u4EF6\u7684\u540D\u79F0??
  12. logfile=??
  13. #\u65E5\u5FD7\u7EA7\u522B??
  14. loglevel=??

轉載于:https://my.oschina.net/newchaos/blog/1555846

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540436.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540436.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540436.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[轉載] java虛擬機 jvm 出入java棧 棧空間內存分配

參考鏈接&#xff1a; Java虛擬機(JVM)堆棧區域 java棧空間是一塊線程私有的內存空間&#xff0c;java堆和程序數據密切相關&#xff0c;那么java棧就是和線程執行密切相關。線程最基本的執行行為就是函數的調用。每次函數調用其實是通過java棧傳遞數據的。 數據結構中的棧的…

SVN命令行更新代碼

命令列表 svn help查看幫助信息 Available subcommands: add auth blame (praise, annotate, ann) cat changeli…

[轉載] Java中Runtime的使用

參考鏈接&#xff1a; Java中的JVM的關閉掛鉤 1 JDK中Runtime的定義 http://blog.csdn.net/lysnow_oss/archive/2007/05/12/1606349.aspx <轉載> 那就首先說點Runtime類吧&#xff0c;他是一個與JVM運行時環境有關的類&#xff0c;這個類是Singleton的。我…

窄帶物聯網(NB-IoT)初步了解

哪有什么天生如此&#xff0c;只是我們天天堅持。既然總有人要贏的話&#xff0c;為什么不能是我呢&#xff1f;[TOC] 什么是NB-Iot? 基于蜂窩的窄帶物聯網&#xff08;Narrow Band Internet of Things, NB-IoT&#xff09;成為萬物互聯網絡的一個重要分支。NB-IoT構建于蜂窩網…

ai人工智能_人工智能能力問答中的人工智能不確定性

ai人工智能1) Which of the following is true with respect to uncertainty in AI systems? Uncertainty arises when we are not 100 percent confident in our decisionsWhenever uncertainty arises, there is needs to be an estimation taken for getting to any conclu…

[轉載] 弄懂JDK、JRE和JVM到底是什么

參考鏈接&#xff1a; JDK JRE和JVM之間的區別 首先是JDK JDK(Java Development Kit) 是 Java 語言的軟件開發工具包(SDK)。 在JDK的安裝目錄下有一個jre目錄&#xff0c;里面有兩個文件夾bin和lib&#xff0c;在這里可以認為bin里的就是jvm&#xff0c;lib中則是jvm工作所需要…

mcq 隊列_人工智能搜索問題能力問題解答(MCQ)

mcq 隊列1) The main Aim of the AI system is to provide a solution for real-life problems by acting and thinking humanly. Whenever an agent is confronted by a problem, what is the first step that it follows towards searching a solution to the problem? Sear…

JavaOne大事紀:IBM談OpenJ9和Open Liberty

JavaOne大會以IBM陳述其最近對開源社區的貢獻作為開場&#xff1a;OpenJ9、Open Liberty和MicroProfile。IBM杰出工程師John Duimovich做了“IBM和Java&#xff1a;助力下一代創新”的開場演講。\\讀者可以回看演講視頻。\\Duimovich說IBM之所以致力于推動Java生態系統的創新&a…

[轉載] JVM中對象的回收過程

參考鏈接&#xff1a; JVM是否創建Main類(具有main()的類)的對象 當我們的程序開啟運行之后就&#xff0c;就會在我們的java堆中不斷的產生新的對象&#xff0c;而這是需要占用我們的存儲空間的&#xff0c;因為創建一個新的對象需要分配對應的內存空間&#xff0c;顯然我的內…

c語言格式對齊填充_C ++中類的大小 課堂上的填充和對齊| 派生類的大小

c語言格式對齊填充Prerequisite: 先決條件&#xff1a; sizeof() operator in C/C C / C 中的sizeof()運算符 Size of struct in C C中的struct大小 We know that a struct size is not only the summation of all the data members, rather its the minimum sum guaranteed. …

ELK系列~對fluentd參數的理解

這段時候一直在研究ELK框架&#xff0c;主要集成在對fluentd和nxlog的研究上&#xff0c;國內文章不多&#xff0c;主要看了一下官方的API&#xff0c;配合自己的理解&#xff0c;總結了一下&#xff0c;希望可以幫到剛入行的朋友們&#xff01; Fluentd&#xff08;日志收集與…

[轉載] Java中的50個關鍵字

參考鏈接&#xff1a; Java平臺如何獨立 Java中的50個關鍵字 關鍵字也稱為保留字&#xff0c;是指java語言中規定了特定含義的標示符。對于保留字&#xff0c;用戶只能按照系統規定的方式使用&#xff0c;不能自行定義。Java中有50個常用關鍵字&#xff1a; 與數據類型相關…

MySQL 直接存儲圖片并在 html 頁面中展示,點擊下載

數據庫實體類&#xff1a; package com.easy.kotlin.picturecrawler.entityimport java.util.* import javax.persistence.*Entity Table(indexes arrayOf(Index(name "idx_url", unique true, columnList "url"),Index(name "idx_category"…

css 文本背景色透明_如何使用CSS將文本或圖像的背景設置為透明?

css 文本背景色透明Introduction: 介紹&#xff1a; In web development, there are numerous ways by which we can style our websites or web pages. You can make use of lots of properties for creating attractive and responsive websites. 在Web開發中&#xff0c;我…

[轉載] 1.1Java使用JDBC原生方式連接MySql數據庫

參考鏈接&#xff1a; Java數據庫連接JDBC驅動程序 前言&#xff1a;今天有朋友問我原生的java連接數據庫&#xff0c;因為框架的使用&#xff0c;如果基礎不牢固的人&#xff0c;是很容易遺忘原生的連接方式。今天正好趁此做一下回顧&#xff1a; 這里只考慮原生方式&#x…

maven安裝及集成myeclipse

第一步&#xff1a;下載和安裝 1、官網下載Maven&#xff1a;http://maven.apache.org/download.cgi 2、解壓到一個文件夾2、設置環境變量&#xff1a;如&#xff1a;M2_HOME&#xff1a;D:\JAVA\apache-maven-3.0.5在path中添加;%M2_HOME%\bin;第二步&#xff1a;和MyEclipse集…

[轉載] Java泛型詳解:<T>和Class<T>的使用。泛型類,泛型方法的詳細使用實例

參考鏈接&#xff1a; Java中的main()函數是強制性的嗎 一、引入 1、泛型是什么 首先告訴大家ArrayList就是泛型。那ArrayList能完成哪些想不到的功能呢&#xff1f;先看看下面這段代碼&#xff1a; [java] view plain copy ArrayList<String> strList new ArrayL…

數字和數字根的總和_使用8086微處理器查找8位數字的數字總和

數字和數字根的總和Problem statement: 問題陳述&#xff1a; Write an assembly language program in 8086 microprocessor to find sum of digit of an 8 bits number using 8 bits operation. 在8086微處理器中編寫匯編語言程序&#xff0c;以使用8位運算找到8位數字的位數…

[轉載] Java筆試題集錦

參考鏈接&#xff1a; 關于Java中文件名和類名的誤解 Java筆試題集錦 1.MVC的各個部分都有那些技術來實現?如何實現? 答&#xff1a;MVC是Model&#xff0d;View&#xff0d;Controller的簡寫。"Model" 代表的是應用的業務邏輯&#xff08;通過JavaBean&#xff…

gcc -pthread_錯誤-在GCC Linux中使用C程序未定義對'pthread_create'的引用

gcc -pthread在Linux中修復對pthread_create的未定義引用 (Fixing undefined reference to pthread_create in Linux) This is a common error while compiling C program in GCC/G Linux. This error occurs when you are using pthread_create function to create threads in…