Java线程与并发编程
基本知识
线程的本质是机器指令的执行路径,它完全是多任务操作系统之上的虚拟概念。从硬件角度来看,每一个CPU只有一条执行路径,成百上千的线程同时运行,只是操作系统调度形成的假象。
每一个计算机程序,或者说进程,至少有一个线程,称为主线程。Java程序的主线程叫…
阅读全文
16 years ago
0
JDBC知识集锦
通过JDBC得到数据字典、数据库元数据信息
下面的例子中,获取到所有表的名称,并进行了截断。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
StringBuffer buff = new StringBuffer(); conn = getConnection(); conn.setAutoCommit( false ); String TABLE_NAME = "TABLE_NAME"; String[] TABLE_TYPES = { "TABLE" }; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables( null, null, null, TABLE_TYPES ); while ( tables.next() ) { String tabName = tables.getString( TABLE_NAME ); buff.append( "TRUNCATE TABLE " + tabName + ";" ); } conn.createStatement().execute( buff.toString() ); conn.commit(); |
如何使用HSQLDB内存模式
1 2 3 |
Class.forName( "org.hsqldb.jdbcDriver" ); Connection conn = DriverManager.getConnection( "jdbc:hsqldb:mem:test", "sa", "" ); conn.createStatement().execute( "SHUTDOWN" ); |
如何使用HSQLDB进程内(In-Process)模式
和内存模式类似,URL为:jdbc:hsqldb:file:/C:/testdb/testDbName 阅读全文
16 years ago
0
log4j配置文件样本
基本配置
属性文件方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
log4j.rootLogger=INFO, Console,File log4j.logger.cc.gmem.demo=INFO log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=[%-5p] [%t] %d{yyyy-MM-dd HH:mm:ss} %l%n%m%n log4j.appender.File=org.apache.log4j.RollingFileAppender log4j.appender.File.File=c:/logs/demo.log log4j.appender.File.Append=true log4j.appender.File.Threshold=ERROR log4j.appender.File.MaxFileSize=256MB log4j.appender.File.MaxBackupIndex=100 log4j.appender.File.layout=org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern=[%-5p] [%t] %d{yyyy-MM-dd HH:mm:ss} %l%n%m%n |
layout
json
依赖于该项目:https://git.gmem.cc/alex/log4j-json-layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out"/> <layout class="org.jetbrains.appenders.JsonLayout"> <param name="excludedFields" value="host,@version" /> </layout> </appender> <category name="cc.gmem"> <priority value="debug"/> </category> <root> <priority value="info"/> <appender-ref ref="console"/> </root> </log4j:configuration> |
阅读全文
16 years ago
0
Velocity学习笔记
代码样例
Velocity宏样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#macro( finHead $head ) #set( $params = $springCtx.getBean('appConfig').params ) <HEAD> <VER>${params.version}</VER> <SRC>${params.srcNode}</SRC> <DES>${params.destNode}</DES> <APP>${params.appName}</APP> <MsgNo>$head.msgNo</MsgNo> <MsgNoOld>$!{head.msgNoOld}</MsgNoOld> <MsgID>$head.msgId</MsgID> <MsgRef>$head.msgRef</MsgRef> <WorkDate>$head.workDate</WorkDate> <Reserve></Reserve> </HEAD> #end |
一个比较复杂的实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping> #foreach($em in $ems) ##循环处理所有实体映射定义 <class entity-name="$em.name" #if($em.node) node="$em.node" #end table="$em.table"> #set($pms = $em.allPropertyMappings) #foreach($pm in $pms) #if($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.IdPropertyMapping")) ##标识符属性 #set($idElName = "id") #if($pm.composite) #set($idElName = "composite-id") #end <$idElName name="$pm.name" #if($pm.node) node="$pm.node" #end #if(not $pm.composite) type="$pm.uniqueKeyMapping.type" #end> #set($kms = $pm.keyMappings) #foreach($km in $kms) #if($pm.composite) <key-property name="$km.name" #if($km.node) node="$km.node" #end type="$km.type" column="$km.column" /> #else <column name="$km.column"/> #end #end <generator class="assigned" /> </$idElName> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.SimplePropertyMapping")) ##简单属性 <property name="$pm.name" #if($pm.node) node="$pm.node" #end type="$pm.type" column="$pm.column" /> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.O2MPropertyMapping")) ##一对多引用 <set name="$pm.name" #if($pm.node) node="$pm.node" #end cascade="all" fetch="join" lazy="false"> <key> #set($kms = $pm.keyMappings) #foreach($km in $kms) <column name="$km.column"/> #end </key> <one-to-many entity-name="$pm.refEntityMapping.name"/> </set> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.M2OPropertyMapping")) ##多对一引用 <many-to-one name="$pm.name" #if($pm.node) node="$pm.node" #end entity-name="$pm.refEntityMapping.name" cascade="all" fetch="join" lazy="false"> #set($kms = $pm.keyMappings) #foreach($km in $kms) <column name="$km.column"/> #end </many-to-one> #elseif($helper.instanceOf($pm,"sparknet.canary.core.mapping.model.M2MPropertyMapping")) ##多对多引用(join-table based) <set name="$pm.name" #if($pm.node) node="$pm.node" #end table="$pm.joinTable" cascade="all" fetch="join" lazy="false"> <key> #set($kms = $pm.keyMappings) #foreach($km in $kms) <column name="$km.column"/> #end </key> <many-to-many entity-name="$pm.refEntityMapping.name"> #set($okms = $pm.oppoKeyMappings) #foreach($okm in $okms) <column name="$okm.column"/> #end </many-to-many> </set> #end #end </class> #end </hibernate-mapping> |
17 years ago
0