BerkeleyDB java的简单使用
关于BerkeleyDB的有点和优点,列在以下
JE offers the following major features:
Large database support. JE databases efficiently scale from one to millions of records. The size of your JE databases are likely to be limited more by hardware resources than by any limits imposed upon you by JE.
Databases are described in Databases.
Database environments. Database environments provide a unit of encapsulation and management for one or more databases. Environments are also the unit of management for internal resources such as the in-memory cache and the background threads. Finally, you
use environments to manage concurrency and transactions. Note that all applications using JE are required to use database environments.Database environments are described in Database Environments.
Multiple thread and process support. JE is designed for multiple threads of control. Both read and write operations can be performed by multiple threads. JE uses record-level locking for high concurrency in threaded applications. Further, JE uses timeouts
for deadlock detection to help you ensure that two threads of control do not deadlock indefinitely.Moreover, JE allows multiple processes to access the same databases. However, in this configuration JE requires that there be no more than one process allowed to write to the database. Read-only processes are guaranteed a consistent, although potentially
out of date, view of the stored data as of the time that the environment is opened.Transactions. Transactions allow you to treat one or more operations on one or more databases as a single unit of work. JE transactions offer the application developer recoverability, atomicity, and isolation for your database operations.
Note that transaction protection is optional. Transactions are described in the Berkeley DB, Java Edition Getting Started with Transaction Processing guide.
In-memory cache. The cache allows for high speed database access for both read and write operations by avoiding unnecessary disk I/O. The cache will grow on demand up to a pre-configured maximum size. To improve your application's performance immediately
after startup time, you can preload your cache in order to avoid disk I/O for production requests of your data.Cache management is described in Sizing the Cache.
Indexes. JE allows you to easily create and maintain secondary indices for your primary data. In this way, you can obtain rapid access to your data through the use of an alternative, or secondary, key.
How indices work is dependent upon the API you are using. If you are using the DPL, seeWorking
with Indices. Otherwise, see Secondary Databases.Log files. JE databases are stored in one or more numerically-named log files in the environment directory. The log files are write-once and are portable across platforms with different endian-ness.
当然也你能看懂个大概。看程序,在程序中大致翻译了一下
package bdb; import java.io.File; import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig; /**
* BerkeleyDB java的简单使用
* @author Xiaohua
*
*/
public class Test { //此数据库的优点
//大数据的支持,能够支持millions的记录,而且更可能是硬件出现瓶颈而不是je
//数据库环境支持。数据库环境能够一次配置多个数据库或者一个数据库;环境也能够管理并发和事务
//多线程和多进程的支持
//支持事务
//支持内存缓存
//支持索引
//日志记录
private static String dbEnv = "D://dbEnv"; public static void main(String[] args) {
Environment myDbEnvironment = null;
Database myDatabase = null;
try {
EnvironmentConfig envConfig = new EnvironmentConfig();// 配置环境变量
envConfig.setAllowCreate(true);
File f=new File(dbEnv);
if(!f.exists()){
f.mkdirs();
}
myDbEnvironment = new Environment(f, envConfig); } catch (DatabaseException dbe) {
}
try {
DatabaseConfig dbConfig = new DatabaseConfig();// 打开数据库
dbConfig.setAllowCreate(true);
myDatabase = myDbEnvironment.openDatabase(null, "myDatabase",
dbConfig); } catch (DatabaseException dbe2) { }
//存储数据
String aKey = "key4";
String aData = "data";
try {
DatabaseEntry theKey = new DatabaseEntry(aKey.getBytes("UTF-8"));
DatabaseEntry theData = new DatabaseEntry(aData.getBytes("UTF-8"));
myDatabase.put(null, theKey, theData);
// myDbEnvironment.sync();
System.out.println(myDatabase.count());
} catch (Exception e) { } // 关闭,应该会自己主动提交
try {
if (myDatabase != null) {
myDatabase.close();
}
if (myDbEnvironment != null) {
myDbEnvironment.cleanLog(); // 在关闭环境前清理下日志
myDbEnvironment.close();
}
} catch (DatabaseException dbe) { }
}
}
BerkeleyDB java的简单使用的更多相关文章
- Java实现简单版SVM
Java实现简单版SVM 近期的图像分类工作要用到latent svm,为了更加深入了解svm,自己动手实现一个简单版的. 之所以说是简单版,由于没实用到拉格朗日,对偶,核函数等等.而 ...
- java实现简单的单点登录
java实现简单的单点登录 摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统当中.本文从业务的角度分析了单点登录的需求和应用领域:从技术本身的角度分析了单点登录技术的内部机制和实现 ...
- Java自定义简单标签
Java自定义简单标签可以方便的在页面输出信息,并且对于权限的控制,和对于Jsp标签和servlet代码的分离有着很好的作用. 下面将以权限的控制为例自定义一个标签: 一.标签类型 <wxt: ...
- 主题:Java WebService 简单实例
链接地址:主题:Java WebService 简单实例 http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...
- java设计模式--简单工厂
java设计模式--简单工厂 简单工厂不是一个标准的设计模式,但是很常用需要掌握. 在java应用开发中,要"面向接口编程". 1.java中接口的概念: 在java中接口是一种特 ...
- JAVA实现简单的四则运算
GitHub 项目地址 https://github.com/745421831/-/tree/master PSP PSP2.1 Personal Software Process Stages 预 ...
- Java的简单类型不能够精确的对浮点数进行运算
由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精确的浮点数运算,包括加减乘除和四舍五入. import java.math.BigDecimal; /** * 由于Java的简单类 ...
- Java秒杀简单设计二:数据库表和Dao层设计
Java秒杀简单设计二:数据库表Dao层设计 上一篇中搭建springboot项目环境和设计数据库表 https://www.cnblogs.com/taiguyiba/p/9791431.html ...
- Java实现简单的RPC框架(美团面试)
一.RPC简介 RPC,全称为Remote Procedure Call,即远程过程调用,它是一个计算机通信协议.它允许像调用本地服务一样调用远程服务.它可以有不同的实现方式.如RMI(远程方法调用) ...
随机推荐
- [HihoCoder1169]猜单词
题目大意: 给你一个数列,问区间[l,r]内与k最接近的数与k的差是多少. 思路: 将数列中的数和询问的数先从小到大排序, 从小到大枚举每个数,如果是数列上的,就加到线段树中, 如果是询问中的,就在线 ...
- ruby -- 修改rubymine的字体大小
rubymine编辑器默认的字体特别小,如何修改rubymine当中的字体大小? 首先,进入 setting\ide setting\editor\colors&fonts\font ...
- extjs form textfield的隐藏方法
只需将textfield的hidden和hideLabel配置为true就可以了.只设置hidden:true时会显示出来一个:的标签. this.formpanel = new Ext.Fo ...
- Apple Developer申请成功
上周日白天,我去申请了Apple Developer.我先是在百度上浏览了一些经验教程,但是点进苹果开发者官网时却发现完全不是那么一回事.盖因它的页面经常在变,如同现在苹果在主推tvOS这个对中国用户 ...
- java反射机制简单介绍
1.字节码.所谓的字节码就是当java虚拟机载入某个类的对象时,首先须要将硬盘中该类的源码编译成class文件的二进制代码(字节码),然后将class文件的字节码载入到内存中,之后再创建该类的对象 2 ...
- 重装Windows系统后,Mysql的恢复
在原地直接恢复MySQL的自动启动的数据库服务,操作如下. (1)环境变量里配置一下Mysql的bin目录 (2)管理员方式启动cmd,运行命令mysqld –install (3)启动Mysql服务 ...
- 【转】C与CPP后缀的文件在编译时的区别
本文出处连接, by Ray FAN(ielnaf@qq.com) ...
- 调用 jdbcTemplate.queryForList 时出现错误 spring-org.springframework.jdbc.IncorrectResultSetColumnCountException
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- android新组件RecyclerView使用介绍和进阶使用,替用Gallery
简介: RecyclerView是support-v7包中的新组件,是一个强大的滑动组件,与经典的ListView相比,同样拥有item回收复用的功能,但是直接把viewholder的实现封装起来,用 ...
- easyui datagrid checkbox multiple columns have been done do
lengku1987 2013-01-06 22:27:47 Sponsored Links easyui datagrid checkbox multiple columns have ...