关于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的简单使用的更多相关文章

  1. Java实现简单版SVM

    Java实现简单版SVM 近期的图像分类工作要用到latent svm,为了更加深入了解svm,自己动手实现一个简单版的.         之所以说是简单版,由于没实用到拉格朗日,对偶,核函数等等.而 ...

  2. java实现简单的单点登录

    java实现简单的单点登录 摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统当中.本文从业务的角度分析了单点登录的需求和应用领域:从技术本身的角度分析了单点登录技术的内部机制和实现 ...

  3. Java自定义简单标签

     Java自定义简单标签可以方便的在页面输出信息,并且对于权限的控制,和对于Jsp标签和servlet代码的分离有着很好的作用. 下面将以权限的控制为例自定义一个标签: 一.标签类型 <wxt: ...

  4. 主题:Java WebService 简单实例

    链接地址:主题:Java WebService 简单实例    http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...

  5. java设计模式--简单工厂

    java设计模式--简单工厂 简单工厂不是一个标准的设计模式,但是很常用需要掌握. 在java应用开发中,要"面向接口编程". 1.java中接口的概念: 在java中接口是一种特 ...

  6. JAVA实现简单的四则运算

    GitHub 项目地址 https://github.com/745421831/-/tree/master PSP PSP2.1 Personal Software Process Stages 预 ...

  7. Java的简单类型不能够精确的对浮点数进行运算

    由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精确的浮点数运算,包括加减乘除和四舍五入. import java.math.BigDecimal; /** * 由于Java的简单类 ...

  8. Java秒杀简单设计二:数据库表和Dao层设计

    Java秒杀简单设计二:数据库表Dao层设计 上一篇中搭建springboot项目环境和设计数据库表  https://www.cnblogs.com/taiguyiba/p/9791431.html ...

  9. Java实现简单的RPC框架(美团面试)

    一.RPC简介 RPC,全称为Remote Procedure Call,即远程过程调用,它是一个计算机通信协议.它允许像调用本地服务一样调用远程服务.它可以有不同的实现方式.如RMI(远程方法调用) ...

随机推荐

  1. [CodeForces-375E]Red and Black Tree

    题目大意: 给你一棵带边权的树,每个结点可能是红色或者黑色,你可以交换若干个点对使得任意一个红点到达与其最近的黑点的距离小于等于m. 思路: 动态规划. f[i][j][k]表示以i为根的子树中,连向 ...

  2. [CodeForces-178F]Representative Sampling

    题目大意: 给你n个字符串,要求从中选出k个字符串,使得字符串两两lcp之和最大. 思路: 动态规划. 首先将所有的字符串排序,求出相邻两个字符串的lcp长度(很显然,对于某一个字符串,和它lcp最长 ...

  3. ZOJ 3707 Calculate Prime S 数论

    思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...

  4. HDU 4183

    给出一个有向图,以及src和dst.判断是否存在从src到dst的两条路径,使得除了src和dst外,没有其它点同时属于两条路径. 给每个点一个为1的点容量(src和dst为2),边的容量也是1,然后 ...

  5. 2015 百度之星 1004 KPI STL的妙用

    KPI Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1754 Description 你 ...

  6. MySQL之thread cache

    最近突然对MySQL的连接非常感兴趣,从status根据thread关键字可以查出如下是个状态 show global status like 'thread%'; +---------------- ...

  7. X-009 FriendlyARM tiny4412 uboot移植之SD Card用起来Kernel boot起来

    <<<<<<<<<<<<<<<<<<<<<<<<< ...

  8. Web前端面试题小集

    一.一个页面上两个div左右铺满整个浏览器,要保证左边的div一直为100px,右边的div跟随浏览器大小变化(比如浏览器为500,右边div为400,浏览器为900,右边div为800),请写出大概 ...

  9. bosondata/chrome-prerender: Render JavaScript-rendered page as HTML/PDF/mhtml/png/jpeg using headless Chrome

    bosondata/chrome-prerender: Render JavaScript-rendered page as HTML/PDF/mhtml/png/jpeg using headles ...

  10. Java代码优化方案 J2ME内存优化

    Java代码优化方案 J2ME内存优化 从几本书上,N个网站上整理的一些JAVA代码优化方案,最近的项目只有1M内存可用,必须很抠门了~J2ME项目更要注意的 避免内存溢出 l 不用的对象释放(置空) ...