数据库连接池的设计思路及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.mzph.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…