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(远程方法调用) ...
随机推荐
- Unity JsonFx 插件使用
在Unity中使用 JsonFx 插件笔记(提示:以下在 Unity3D v5.4.0 版本 Win 平台下测试成功) 下载 JsonFx 插件注意:JsonFx 插件其实就是一个 dll 文件(如果 ...
- PIL The _imaging C module is not installed
今天在WIN 7 64位用PIL的时候,提示 The _imaging C module is not installed ,原来是需要安装64位的. 刚开始安装的是这个:http://www.pyt ...
- hdu 1024 Max Sum Plus Plus DP
Max Sum Plus Plus Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
- JQ自定义下拉列表插件
自从上次做了JQ自定义分页插件和表格插件后,就没在自定义过插件了,这一个月都在用linq和ef,基本前端都没怎么去碰了,今天有个同事说有个项目需要在下拉框里面带有复选框,本来想网上找下插件的,一想,其 ...
- 用Java实现HTTP Multipart的服务端和客户端
今天简单介绍一下如何用Java支持HTTP Multipart的request和response. 整个项目的代码可以在https://github.com/mcai4gl2/multi下载. 在这个 ...
- 在Mac系统上安装Tomcat
到 apache官方主页 下载 Mac 版本的完整 .gz文件包.解压拷贝到 /Library目录下. 1.Mac中 Finder打开 Library的方法 新建 Finder窗口 按下 sh ...
- jQuery EasyUI API 中文文档 - Panel面板
<html> <head> <title>布局管理器--控制面板</title> <script src="jquery-easyui/ ...
- linux 编译win32程序
apt-get install mingw32 int main(int argc, char *argv) { printf("Windows Compiler Test\n") ...
- Linux 网络设备驱动开发(一) —— linux内核网络分层结构
Preface Linux内核对网络驱动程序使用统一的接口,并且对于网络设备采用面向对象的思想设计. Linux内核采用分层结构处理网络数据包.分层结构与网络协议的结构匹配,既能简化数据包处理流程,又 ...
- SQL Server 2008新特性——策略管理
策略管理是SQL Server 2008中的一个新特性,用于管理数据库实例.数据库以及数据库对象的各种属性.策略管理在SSMS的对象资源管理器数据库实例下的“管理”节点下,如图: 从图中可以看到,策略 ...