jndi

数据库连接池

你说的曾经没有我的故事 提交于 2019-11-30 12:17:03
这两天公司的事情不忙,看了一下ssh的框架,在看spring框架的时候看到数据源这一块。就想知道数据源这一块是怎么实现的,以前也有学习过数据源,但感觉没那么系统。在网上看到一个详细介绍数据库连接池的,摘抄记录一下。 一、应用程序直接获取数据库连接的缺点   用户每次请求都需要向数据库获得链接,而数据库创建连接通常需要消耗相对较大的资源,创建时间也较长。假设网站一天10万访问量,数据库服务器就需要创建10万次连接,极大的浪费数据库的资源,并且极易造成数据库服务器内存溢出、拓机。如下图所示:    二、使用数据库连接池优化程序性能 2.1、数据库连接池的基本概念    数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现的尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正式针对这个问题提出来的. 数据库连接池负责分配,管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是重新建立一个 。如下图所示:    数据库连接池在初始化时将创建一定数量的数据库连接放到连接池中, 这些数据库连接的数量是由最小数据库连接数来设定的.无论这些数据库连接是否被使用,连接池都将一直保证至少拥有这么多的连接数量.连接池的最大数据库连 接数量限定了这个连接池能占有的最大连接数

JNDI注入与反序列化学习总结

余生颓废 提交于 2019-11-30 12:10:40
0x01.java RMI RMI(Remote Method Invocation)是专为Java环境设计的远程方法调用机制,远程服务器实现具体的Java方法并提供接口,客户端本地仅需根据接口类的定义,提供相应的参数即可调用远程方法。RMI依赖的通信协议为JRMP(Java Remote Message Protocol ,Java 远程消息交换协议),该协议为Java定制,要求服务端与客户端都为Java编写。这个协议就像HTTP协议一样,规定了客户端和服务端通信要满足的规范。在RMI中对象是通过序列化方式进行编码传输的。 如上图所示,在JVM之间通信时,客户端要调用远程服务器上的对象时,并不是直接将远程对象拷贝到本地,而是通过传递一个stub。 其中stub就包含了远程服务器的地址和端口等信息,可以看作是远程对象的引用,客户端可以通过调用stub中的方法来对远程对象进行使用,也就是上图所说的逻辑上的调用,而非直接调用,即真实的数据是从客户端到服务端远程对象的stub(存根)到服务器的skeleton(骨架)之间的socket通信。 实际上client并不知道远程服务器的通信地址和端口,但是服务器对象存根(stub)中有这些信息,那么客户端只要拿到stub,通过调用stub上的方法,然后stub再连接到远程服务器的具体端口,服务器执行client所请求的具体方法

Out of container JNDI data source

佐手、 提交于 2019-11-30 11:28:53
I would like to configure a DataSource using JNDI in a Java SE app. What is the best way to do this? So far, I've come across 2 projects: Apache Naming . The project page has a specific example for configuring a data source, but it looks like the project is super old and no longer active. JBossNS . It looks like it's easy to configure a local-only JNDI using LocalOnlyContextFactory , but I haven't found any docs on how to actually configure a data source. If possible, I would like to also configure the data source with a JTA transaction manager (using JOTM?). Why are you using JNDI for this?

How do I lookup a JNDI Datasource from outside a web container?

孤人 提交于 2019-11-30 10:26:52
问题 I have the following environment set up: Java 1.5 Sun Application Server 8.2 Oracle 10 XE Struts 2 Hibernate I'm interested to know how I can write code for a Java client (i.e. outside of a web application) that can reference the JNDI datasource provided by the application server. The ports for the Sun Application Server are all at their defaults. There is a JNDI datasource named jdbc/xxxx in the server configuration, but I noticed that the Hibernate configuration for the web application uses

Java ldap authentication issue

余生颓废 提交于 2019-11-30 09:37:54
I'm trying to have my custom java application use our Active Directory Server for authentication but I cannot get it to work for some reason. Can anyone see why this is? Here is my method below: private boolean authenticate(String serverName, String userId, String password) throws NamingException { DirContext ctx = null; Hashtable env = new Hashtable(11); boolean b = false; try { env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://servername.org:389"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY

Spring Jndi Context and PropertyPlaceholderConfigurer

允我心安 提交于 2019-11-30 09:00:59
问题 Using Spring, I want to read a variable inside the context of Webspehere. Read a Environment Variable in Java with Websphere To define the data.... inside web.xml <env-entry> <env-entry-name>varName</env-entry-name> <env-entry-value>56</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> To see with java Context envEntryContext = (Context) new InitialContext().lookup("java:comp/env"); String mydata = (String)envEntryContext.lookup(“varName”); But I want take the

javax.naming.CommunicationException: simple bind failed

戏子无情 提交于 2019-11-30 08:26:44
When trying to connect to the LDAP server using a simple LDAP application I am getting an error which says "simple bind failed". I am assuming this is related to some sort of BIND. I have a bind property in one of the property file for a different application, but am not sure how to pass on that property to this program. Do I need to add any further details? Code import javax.naming.directory.*; import javax.naming.*; import java.util.Vector; import java.util.Enumeration; import java.util.Properties; public class SearchLDAP { public static void main(String[] args) { String base = ""; String

javax.naming.NameNotFoundException: Unable to resolve 'MyDB'. Resolved '' Weblogic 12.1.3. c

走远了吗. 提交于 2019-11-30 08:23:45
问题 While migrating from Tomcat to Weblogic 12.1.3 I got this exception javax.naming.namenotfoundexception while trying to look up then I have tried the following : NameNotFoundException: While trying to lookup 'jdbc' only when publishing from Eclipse Kepler but not Indigo and How to access JNDI data source defined in weblogic 10.3.6 I got the in titled error now My lookup code ds = (DataSource) initContext.lookup("MyDB"); in weblogic JNDI Name MyDB Any help please? 回答1: Unlike Tomcat, weblogic

java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool DataSourceFactory

守給你的承諾、 提交于 2019-11-30 06:34:01
问题 I'm investigating moving away from an Oracle connection pool and using the Tomcat connection pool. I followed the myriad of example for configuring the <Resource> in Tomcat's /conf/server.xml . I found great info here. However, when I start Tomcat, I get the following error: javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool DataSourceFactory] I'm using Tomcat 6.0. My <Resource> config in /conf

Associate Ldap user to a group with Java

房东的猫 提交于 2019-11-30 05:45:58
问题 I'm having problems to find how to associate a #Ldap user to a given group. That is what I have tried: Attributes attrs = new BasicAttributes(); BasicAttribute basicAttrs = new BasicAttribute("objectclass"); basicAttrs.add("top"); basicAttrs.add("person"); BasicAttribute memberOf = new BasicAttribute("memberOf"); memberOf.add("Managers"); // Tried with distinguished name too memberOf.add("Administrators"); // Tried with distinguished name too attrs.put(basicAttrs); attrs.put("cn", user