java中Properties有什么用,举例说明?

3.9 Properties的用法 

马克-to-win:Properties里面存着也是键值对,而且它更方便java对配置文件,字符串的操作,

例:3.9.1


import java.util.*;
public class TestMark_to_win {
    public static void main(String args[]) {
        Properties sala = new Properties();
        Set name;
        String str;
        sala.put("zs", "1111");
        sala.put("ls", "2222");
        sala.put("ww", "3333");
        sala.put("zl", "4444");

        // Show all name and sala in hashtable.
        name = sala.keySet(); // get set-view of keys
        Iterator itr = name.iterator();
        while (itr.hasNext()) {
            str = (String) itr.next();
            System.out.println("The sala of " +
            /* public String getProperty(String key)Searches for the property
             * with the specified key in this property list.*/
            str + " is " + sala.getProperty(str) + ".");
 
更多请见:https://blog.csdn.net/qq_44639795/article/details/103087533

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在GlassFish,Thread Pool被用于管理应用程序的并发请求。以下是在GlassFish使用Thread Pool的一个简单示例: 1. 首先,你需要在GlassFish创建一个Thread Pool。你可以使用GlassFish控制台或命令行工具来完成这个任务。例如,使用控制台,你可以依次点击“Configurations”、“server-config”、“Thread Pools”、“New”来创建一个新的Thread Pool。 2. 然后,你需要在你的应用程序使用这个Thread Pool。你可以使用Java EE的@ManagedExecutorService注解来注入一个Thread Pool,或者使用Java的ExecutorService接口来手动创建一个Thread Pool。例如,下面是使用@ManagedExecutorService注解的示例: ``` import javax.annotation.Resource; import javax.enterprise.concurrent.ManagedExecutorService; import javax.enterprise.context.ApplicationScoped; @ApplicationScoped public class MyService { @Resource private ManagedExecutorService executor; public void doSomething() { executor.submit(() -> { // 处理请求的代码 }); } } ``` 在这个示例,我们注入了一个ManagedExecutorService对象,并将其用于处理请求。当我们调用doSomething()方法时,我们使用线程池执行一个Lambda表达式,该表达式包含了我们要处理的请求。 3. 最后,你需要配置Thread Pool的属性。你可以在GlassFish控制台编辑Thread Pool的属性,或者在应用程序的persistence.xml文件使用Java EE的concurrency元素来配置Thread Pool的属性。例如,下面是在persistence.xml文件配置Thread Pool的示例: ``` <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="my-pu"> <jta-data-source>jdbc/mydb</jta-data-source> <properties> <property name="javax.persistence.concurrent.max-thread-pool-size" value="10"/> <property name="javax.persistence.concurrent.timeout" value="5000"/> </properties> </persistence-unit> </persistence> ``` 在这个示例,我们在persistence.xml文件配置了Thread Pool的最大线程数和超时时间。这些属性将被用于管理我们的并发请求。 总之,使用Thread Pool可以在GlassFish提高应用程序的性能和可伸缩性。你可以使用Java EE的@ManagedExecutorService注解或Java的ExecutorService接口来使用Thread Pool,并使用GlassFish控制台或应用程序的persistence.xml文件来配置Thread Pool的属性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mark_to_win

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值