Decompression
1 | tar -xvf zookeeper-3.5.2-alpha.tar.gz |
Test
1 | ./zkServer.sh start |
1 | tar -xvf zookeeper-3.5.2-alpha.tar.gz |
1 | ./zkServer.sh start |
1 | . |
add dependency
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
add app config
1 | <?xml version="1.0" encoding="UTF-8"?> |
container action
1 | package com.leon; |
1 | CREATE TABLE `user_org` ( |
User find_in_set
function directly.1
select * from user_org where find_in_set('1003', organizations);
LIKE
key word:1 | select * from user_org where organizations like '%1003%'; |
this may mis match, if element length are not fixed.
1 | CREATE OR REPLACE |
ibatis3.x change name to mybatis.
mybatis could package N+1
query problem, in <association>
and <collection>
ibatis2 use nest query
is a brute method, we can package in DAO or service as will.
But mybatis N+1
query not support paging query.
May be 1 to many is difficult to implements in framework,
and the number you want can’t be predict.
In ibatis2.x, we need to write
which xml mapping file is the DAO implements class binding.
In mybatis DAO interface’s name automatically binding
implements with xml file.
ps. although mybatis support annotation way config DAO,
but it loose flexibility, and invade code too much.
sqlMapConfig
, mybatis is configuration
sqlMap
,mybatis use mappers
.in ibatis namespace is not necessary, and has no meaning.
in mybatis it mean file’s corresponding DAO interface.
ibatis has resultMap
resultClass
two return typesresultMap
mean self define class, resultClass
nean java class.
mybatis union these too resultType
.
ibatis use parameterClass
, mybatis use parameterType
parameter difference
mybatis use OGNL
expression.
1 | # ibatis |
ibatis use <procedure>
tag call precedure process.1
2
3
4
5
6
7
8
9<parameterMap id="reduceParameters" class="map">
<parameter property="id" jdbcType="INTEGER" javaType="java.lang.Integer" mode="IN"/>
<parameter property="firstName" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
<parameter property="lastName" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
</parameterMap>
<procedure id="reduceGroupNumber" parameterMap="reduceParameters">
{call reduce_group_number (?, ?, ?)}
</procedure>
In mybatis <proccedure>
has been removed,
<select>
<insert>
<update>
replaced.
1 | <select id="reduceGroupNumber" parameterMap="reduceParameters" statementType="CALLABLE"> |
statementType="CALLABLE"
show it’s not a usual sql request.
ibatis:1
2
3
4<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sqlMap-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
mybatis:1
2
3
4
5<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:com/leon/core/config/mybatis-config.xml" />
<property name="mapperLocations" value="classpath*:com/leon/**/*Mapper.xml" />
</bean>
SqlMapClient
to SqlSessionFactory
TypeHandlerCallback
to TypeHandler
DataSourceFactory
move to org.apache.ibatis.datasource
packageORA-00257: archiver error. Connect internal only, until freed
login in sys
sqlplus sys/pass@tt as sysdba
find archiv log
positionSQL> show parameter log_archive_dest;
if value is null, check directorySQL> archive log list;
check flash recovery area
use conditionSQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
find recovery directorySQL> show parameter recover;
remove log file in no use.
caution: reserver file remain in time.
rman maintainrman target sys/pass
check archivelog in no useRMAN> crosscheck archivelog all;
delete expired file in dbRMAN> delete expired archivelog all;
RMAN> delete archivelog until time 'sysdate-1';
check againSQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
if archive log
model can’t startup,
recover to noarchive log
startup then shutdown.
1 | shutdown immediate; |
turn to archive log
again
1 | shutdown immediate; |
If still can’t modify startup.
Try to delete more log or expand space.
1 | ## check log group |
For example, when a sheet have about 1 million record need import in to database.
How to do this.
1 | insert into zoo_sea (id, name, age, birthday, status) |
make 1 million data into 10000 sql command, insert can finish with in 20 minutes.
Oracle is different with Mysql or sqlServer, it need client connect to DB server. But mysql or sqlServer can connect DB server with specific ip connect.
open Net Manager
Oracle Net Config
Local
Service Naming
click add
config new net service.
It actually add a config in this file:E:\Oracle\product\10.2.0\client_1\NETWORK\ADMIN\tnsnames.ora
1 |
|
If install server and client in one machine, server directory will have same config file.
D:\Oracle\product\10.2.0\db_1\NETWORK\ADMIN\tnsnames.ora
So when config done Net Manager
connnet to oracle, ORA-12154
may happen.
Then you should doubt, which config PL/SQL use.
In this time use tnsping
command.
This problem coursed by install sequence
If install DB service first, Client next, then this problem will not happen**
If PL/SQL’s insatll directory have ()
like 64bit system Program Files (x86)
,
then no matter how you adjust config, it always alert ORA-12154
.
So check software’s insatll path can avoid this problem.
Memcached is multi-thread, not block reuse IO net model.
it has main listen thread main worker sub thread.
‘leader’ listened net connnect, dispatch to worker thread.
In network layer, memcached use libevent package event.
But this bring concurrency and lock problem, like stats
command.
Redis reuse single thread IO model, it’s self package a AeEvent event framework.
It implements epoll
kqueue
select
event,
for simple IO operation, single thread can reach the top speed.
But for some calc operation, this affect global throughput alot.
Memcached use prepare way to manage memory.
In this way memory pool can avoid the cost in apply and release memory.
Redis use real-time way to manage memory.
Memcached provide cas
command, it can make sure data consistency.
Redis has no cas
command, but it provide transaction function.
It make sure series of commands’ atomicity, it wouldn’t be interrupted.
Memcached only support key-value
storage,
not support enumerate / persistence/ copy and so on function.
Redis support except key-value
way, but list
set
sorted
set
hash
.
In other hand, redis support data persistence, copy and so on function.
When data in-memory use Redis is better.
Redis in alot of place play a role in replace Memcached.
When need other data structure, Redis is better.
When storage data can’t be remove, Redis is better.
ClassLoader
.ThreadLocal
storage [thread reference?] or [object reference?]static reference hold container.
1 | class Holder { |
call long String’s intern()
method
1 | String src = "......"; |
forgot release resource
1 | try { |
forgot close door
1 | try { |
GC can’t reach like native
true memory
Web container in application contextgetServletContext().setAttribute("rubbish", map);
no reboot and not remove rubbish.
Web container in session contextsession.setAttribute("rubbish", map);
no reboot / not invalid and not remove rubbish.
Not right JVM option
IBM JDK noclassgc
option, it stop no use class’s garbage collect.
If HashSet’s element object have no standard implement
or no implement of equals()
and hashCode()
.
Collection can’t ignore repeated element.
Thread inherited ContextClassLoader
or ccessControlContext
,
and use ThreadGroup
or InheritedThreadLocal
.
They affect java.util.concurrent.Executor
Not use ThreadLocal
as cache unless truly necessary.
If thread not in it’s life cycle, load ContextClassLoader
, gc can’t reach it.
When ThreadGroup
have no subThread
but have sub ThreadGroup
call ThreadGroup.destroy()
.
It lead to this sub ThreadGroup
can’t remove from it’s parent ThreadGroup
.
use WeakHashMap, value hold key reference..
NIO
is make up for IO
‘s lack
NIO have some new characters:
no block i/o, selector, buffer and channelChannel
Buffer
Selector
is the main force.
Channel
like Stream in traditional style java.
Buffer
1 | ByteBuffer byte |
Selector
Used to listen mulity channel’s event.
In traditional tyle when i/o unblock, we know we can i/o.
But use NIO, we need this equipment to manage i/o.
NIO operate a type of data block, it’s bigger than a byte[maybe].
read()
or write()
,To NIO when a thread send a request, but no response.
It’s a free, it can do any other tasks, until selector call.
NIO’s disadvantage is it need to check buffer space everytime.
Because it design for block, if block is not completed,
there is no meaning to operate data.
NIO fit for thousands short link and little data.
IO fit for few long link and big data.
Three guys got a task, to drink 50L water.
They all got a 100ml break. Have three water taps, it has no valve,
occasionally 100ml water flow out.
So these three poor guys have to wait until drink 500 cup of break.
But if they have a plumber to manage these water tap, thing wil be big different.
Use this mechanism guy need to come and drink 5 times bucket.
If the water tap’s water flow is very strong,
then this mechanism is not good.
Because plumber’s manage tap needs time, and it’s buckets needs space.
So in this condition, these guys waiting for break
be filled with water and drink is a better chooice.