Summer Review and Course Design —— 1. Reflection and connection pool

Java反射与连接池解析
本文深入探讨Java反射机制,介绍其如何获取类的构造方法、成员变量等信息,并通过实例展示其应用。同时,文章详细解释数据库连接池的概念与工作原理,分析其在大型程序中提高效率的作用。

I am so lazy…
Well, I’m back after a month.

The new section of my blog is the Summer Review and Course Design.
Today I will describe the Reflection and Connection pool in JAVA.


1.Reflection
Java reflection is an new mechanism which is used to get the detail information about the Construction method, mumber variables and normal methods in a Class. Well, the precondition is that the mechanism have to depend on the following two document:

  1. the API belong to the package java.lang.reflect
  2. the Class Class belong to the package Java.lang

eg. We can new a new package——reflect——and a new class to examine the function of reflection.
If you want to know something about the unknown class, for example, Class “driverClass”, you can compile the following code.
在这里插入图片描述

run as java application and you will see the information you want
在这里插入图片描述

-------------------------------------------------------------------------------------------------------
2.the connection pool

Before discussing the new defination, let’s talking about the database-linked method we used now.

In the previous program, as long as we need to link to the database, the Driver have to be loaded in the tool class. After that, we can get the database connection through the DriverManager.

In this process, as long as we want to operate something through the database, we must get the database connection, which means that we have to find the database Host throw the url again and again. The process of looking for the address will consume much of time.

The connection pool is not a necessity in a little program, however, in a large program, the complicated and repeated request towards the database will occupy plenty of time as we discussed just now. Therefore, we need the connection pool to simplify and accelerate the process in this case.

Now let’s assume there is a pool, which can communicat with the database server as soon as initialization. And caches …let’s say…5 DB connection waiting for use.

So, if we have such a pool, when there’s in need, APP Server need not to request the database server again and again, waiting so much time. APP Server only need to communicate with the connection pool and access to the cached connection off the shelf. It will saving numorous time in a large program.

The simple principle has been discussed. And you can also refer to the following picture to deepen understanding.
在这里插入图片描述
EMMMMMMM…

As for how to acheive the connection pool and the configuration…
Let’s reconsideration…
Tommorow high probability.
Good night…though I will stay up late high probability…

connection pool连接池
mechanism 机制
precondition前提,事先具备条件
database server数据库服务器
initialization初始化
cache缓存。。。这个单词竟然忘了。。。难道我忘了被计组支配的恐惧了么。。。
off the shelf现成的
principle原理
reference参考
configuration配置
reconsideration再议。。。

Error L6200E: Symbol **`msg`** multiply defined by `can.o` and `main.o` indicates that the symbol **`msg`** is defined in both object files `can.o` and `main.o`. This is a common issue in C/C++ projects when global variables are declared in header files without using the `extern` keyword, leading to multiple definitions during the linking phase. ### 原因分析 - **Multiple Definitions**: When a global variable is defined in a header file and that header is included in multiple source files, each source file gets its own definition of that variable. As a result, when the linker tries to combine all object files, it finds multiple instances of the same symbol and reports an error [^3]. - **Improper Use of `extern`**: To declare a global variable that is shared across multiple files, the correct approach is to use the `extern` keyword in the header file and define the variable in only one source file [^2]. ### 解决方案 #### 1. Use `extern` in the Header File If `msg` is declared in a header file (e.g., `global.h`), change its declaration to use the `extern` keyword: ```c // global.h #ifndef GLOBAL_H #define GLOBAL_H extern char msg[]; // Declaration only #endif // GLOBAL_H ``` #### 2. Define the Variable in a Single Source File In one source file (e.g., `main.c` or `global.c`), define the variable: ```c // main.c or global.c #include "global.h" char msg[] = "Hello, world!"; // Actual definition ``` #### 3. Ensure No Duplicate Definitions Make sure that no other source file defines `msg`. If `can.c` or any other file has a definition like `char msg[] = "...";`, remove it or ensure it is only declared with `extern`. #### 4. Check for Multiple Inclusions Ensure that the header file containing the `extern` declaration is not included multiple times unintentionally. Using include guards or `#pragma once` can help prevent this issue [^1]. #### 5. Linker Configuration If the error persists and the symbol is defined in different libraries, verify the linker settings and ensure that no conflicting libraries are being linked. This is particularly important if the project uses third-party libraries or mixes single-threaded and multithreaded runtime libraries [^3]. --- ### 示例代码 #### Header File (`global.h`) ```c #ifndef GLOBAL_H #define GLOBAL_H extern int shared_value; #endif // GLOBAL_H ``` #### Source File (`main.c`) ```c #include "global.h" int shared_value = 0; // Definition int main() { shared_value = 42; return 0; } ``` #### Another Source File (`helper.c`) ```c #include "global.h" void print_value() { printf("Value: %d\n", shared_value); } ``` --- ### 编译与链接命令(示例) ```bash gcc -c main.c -o main.o gcc -c helper.c -o helper.o gcc main.o helper.o -o program ``` --- ### 总结 To resolve the **Error L6200E: Symbol `msg` multiply defined by `can.o` and `main.o`**, ensure that global variables are declared with `extern` in header files and defined in only one source file. Avoid defining the same variable in multiple translation units, and verify that the project configuration does not introduce conflicts through libraries or runtime settings [^1]. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值