barriers / 阅读 / 详情

java 哪个锁是非重入的

2023-07-25 12:20:16
TAG: ava ja java
共2条回复
康康map

读写锁 ReadWriteLock读写锁维护了一对相关的锁,一个用于只读操作,一个用于写入操作。只要没有writer,读取锁可以由多个reader线程同时保持。写入锁是独占的。

互斥锁一次只允许一个线程访问共享数据,哪怕进行的是只读操作;读写锁允许对共享数据进行更高级别的并发访问:对于写操作,一次只有一个线程(write线程)可以修改共享数据,对于读操作,允许任意数量的线程同时进行读取。

与互斥锁相比,使用读写锁能否提升性能则取决于读写操作期间读取数据相对于修改数据的频率,以及数据的争用——即在同一时间试图对该数据执行读取或写入操作的线程数。

读写锁适用于读多写少的情况。

可重入读写锁 ReentrantReadWriteLock

属性ReentrantReadWriteLock 也是基于 AbstractQueuedSynchronizer 实现的,它具有下面这些属性(来自Java doc文档):

* 获取顺序:此类不会将读取者优先或写入者优先强加给锁访问的排序。

* 非公平模式(默认):连续竞争的非公平锁可能无限期地推迟一个或多个reader或writer线程,但吞吐量通常要高于公平锁。

* 公平模式:线程利用一个近似到达顺序的策略来争夺进入。当释放当前保持的锁时,可以为等待时间最长的单个writer线程分配写入锁,如果有一组等待时间大于所有正在等待的writer线程的reader,将为该组分配读者锁。

* 试图获得公平写入锁的非重入的线程将会阻塞,除非读取锁和写入锁都自由(这意味着没有等待线程)。

* 重入:此锁允许reader和writer按照 ReentrantLock 的样式重新获取读取锁或写入锁。在写入线程保持的所有写入锁都已经释放后,才允许重入reader使用读取锁。

writer可以获取读取锁,但reader不能获取写入锁。

* 锁降级:重入还允许从写入锁降级为读取锁,实现方式是:先获取写入锁,然后获取读取锁,最后释放写入锁。但是,从读取锁升级到写入锁是不可能的。

* 锁获取的中断:读取锁和写入锁都支持锁获取期间的中断。

* Condition 支持:写入锁提供了一个 Condition 实现,对于写入锁来说,该实现的行为与 ReentrantLock.newCondition() 提供的Condition 实现对 ReentrantLock 所做的行为相同。当然,此 Condition 只能用于写入锁。

读取锁不支持 Condition,readLock().newCondition() 会抛出 UnsupportedOperationException。

* 监测:此类支持一些确定是读取锁还是写入锁的方法。这些方法设计用于监视系统状态,而不是同步控制。

实现AQS 回顾在之前的文章已经提到,AQS以单个 int 类型的原子变量来表示其状态,定义了4个抽象方法( tryAcquire(int)、tryRelease(int)、tryAcquireShared(int)、tryReleaseShared(int),前两个方法用于独占/排他模式,后两个用于共享模式 )留给子类实现,用于自定义同步器的行为以实现特定的功能。

对于 ReentrantLock,它是可重入的独占锁,内部的 Sync 类实现了 tryAcquire(int)、tryRelease(int) 方法,并用状态的值来表示重入次数,加锁或重入锁时状态加 1,释放锁时状态减 1,状态值等于 0 表示锁空闲。

对于 CountDownLatch,它是一个关卡,在条件满足前阻塞所有等待线程,条件满足后允许所有线程通过。内部类 Sync 把状态初始化为大于 0 的某个值,当状态大于 0 时所有wait线程阻塞,每调用一次 countDown 方法就把状态值减 1,减为 0 时允许所有线程通过。利用了AQS的共享模式。

现在,要用AQS来实现 ReentrantReadWriteLock。

一点思考问题

* AQS只有一个状态,那么如何表示 多个读锁 与 单个写锁 呢?

* ReentrantLock 里,状态值表示重入计数,现在如何在AQS里表示每个读锁、写锁的重入次数呢?

* 如何实现读锁、写锁的公平性呢?

cloudcone
* 回复内容中包含的链接未经审核,可能存在风险,暂不予完整展示!

不可重入锁,与可重入锁相反,不可递归调用,递归调用就发生死锁。看到一个经典的讲解,使用自旋锁来模拟一个不可重入锁,代码如下

import java.util.concurrent.atomic.AtomicReference;

public class UnreentrantLock {

private AtomicReference<Thread> owner = new AtomicReference<Thread>();

public void lock() {

Thread current = Thread.currentThread();

//这句是很经典的“自旋”语法,AtomicInteger中也有

for (;;) {

if (!o***.compareAndSet(null, current)) {

return;

}

}

}

public void unlock() {

Thread current = Thread.currentThread();

o***.compareAndSet(current, null);

}

}

代码也比较简单,使用原子引用来存放线程,同一线程两次调用lock()方法,如果不执行unlock()释放锁的话,第二次调用自旋的时候就会产生死锁,这个锁就不是可重入的,而实际上同一个线程不必每次都去释放锁再来获取锁,这样的调度切换是很耗资源的。

相关推荐

countdownlatch的await超时时间设置多少合适

CountDownLatch是一个同步辅助类,犹如倒计时计数器,创建对象时通过构造方法设置初始值,调用CountDownLatch对象的await()方法则处于等待状态,调用countDown()方法就将计数器减1,当计数到达0时,则所有等待者或单个等待者开始执行。
2023-07-24 20:05:581

Java编写程序,分别使用顺序流和并行流计算10,、20、30和40这几个数的阶乘,输出结果及完成计算的时间。

我、提、供、编、码。
2023-07-24 20:06:183

Java线程安全和非线程安全

  ArrayList和Vector有什么区别?HashMap和HashTable有什么区别?StringBuilder和StringBuffer有什么区别?这些都是Java面试中常见的基础问题 面对这样的问题 回答是 ArrayList是非线程安全的 Vector是线程安全的 HashMap是非线程安全的 HashTable是线程安全的 StringBuilder是非线程安全的 StringBuffer是线程安全的 因为这是昨晚刚背的《Java面试题大全》上面写的 此时如果继续问 什么是线程安全?线程安全和非线程安全有什么区别?分别在什么情况下使用?这样一连串的问题 一口老血就喷出来了…   非线程安全的现象模拟   这里就使用ArrayList和Vector二者来说明   下面的代码 在主线程中new了一个非线程安全的ArrayList 然后开 个线程分别向这个ArrayList里面添加元素 每个线程添加 个元素 等所有线程执行完成后 这个ArrayList的size应该是多少?应该是 个?   [java]   public class Main   {   public static void main(String[] args)   {   // 进行 次测试   for(int i = ; i < ; i++)   {   test();   }   }   public static void test()   {   // 用来测试的List   List<Object> list = new ArrayList<Object>();   // 线程数量( )   int threadCount = ;   // 用来让主线程等待threadCount个子线程执行完毕   CountDownLatch countDownLatch = new CountDownLatch(threadCount);   // 启动threadCount个子线程   for(int i = ; i < threadCount; i++)   {   Thread thread = new Thread(new MyThread(list countDownLatch));   thread start();   }   try   {   // 主线程等待所有子线程执行完成 再向下执行   countDownLatch await();   }   catch (InterruptedException e)   {   e printStackTrace();   }   // List的size   System out println(list size());   }   }   class MyThread implements Runnable   {   private List<Object> list;   private CountDownLatch countDownLatch;   public MyThread(List<Object> list CountDownLatch countDownLatch)   {   this list = list;   untDownLatch = countDownLatch;   }   public void run()   {   // 每个线程向List中添加 个元素   for(int i = ; i < ; i++)   {   list add(new Object());   }   // 完成一个子线程   untDown();   }   }   public class Main   {   public static void main(String[] args)   {   // 进行 次测试   for(int i = ; i < ; i++)   {   test();   }   }   public static void test()   {   // 用来测试的List   List<Object> list = new ArrayList<Object>();   // 线程数量( )   int threadCount = ;   // 用来让主线程等待threadCount个子线程执行完毕   CountDownLatch countDownLatch = new CountDownLatch(threadCount);   // 启动threadCount个子线程   for(int i = ; i < threadCount; i++)   {   Thread thread = new Thread(new MyThread(list countDownLatch));   thread start();   }   try   {   // 主线程等待所有子线程执行完成 再向下执行   countDownLatch await();   }   catch (InterruptedException e)   {   e printStackTrace();   }   // List的size   System out println(list size());   }   }   class MyThread implements Runnable   {   private List<Object> list;   private CountDownLatch countDownLatch;   public MyThread(List<Object> list CountDownLatch countDownLatch)   {   this list = list;   untDownLatch = countDownLatch;   }   public void run()   {   // 每个线程向List中添加 个元素   for(int i = ; i < ; i++)   {   list add(new Object());   }   // 完成一个子线程   untDown();   }   }   上面进行了 次测试(为什么要测试 次?因为非线程安全并不是每次都会导致问题)   输出结果                                 上面的输出结果发现 并不是每次测试结果都是 有好几次测试最后ArrayList的size小于 甚至时不时会抛出个IndexOutOfBoundsException异常 (如果没有这个现象可以多试几次)   这就是非线程安全带来的问题了 上面的代码如果用于生产环境 就会有隐患就会有BUG了   再用线程安全的Vector来进行测试 上面代码改变一处 test()方法中   [java]   List<Object> list = new ArrayList<Object>();   List<Object> list = new ArrayList<Object>();改成   [java]   List<Object> list = new Vector<Object>();   List<Object> list = new Vector<Object>();   再运行程序   输出结果                                 再多跑几次 发现都是 没有任何问题 因为Vector是线程安全的 在多线程操作同一个Vector对象时 不会有任何问题   再换成LinkedList试试 同样还会出现ArrayList类似的问题 因为LinkedList也是非线程安全的   二者如何取舍   非线程安全是指多线程操作同一个对象可能会出现问题 而线程安全则是多线程操作同一个对象不会有问题   线程安全必须要使用很多synchronized关键字来同步控制 所以必然会导致性能的降低   所以在使用的时候 如果是多个线程操作同一个对象 那么使用线程安全的Vector 否则 就使用效率更高的ArrayList   非线程安全!=不安全   有人在使用过程中有一个不正确的观点 我的程序是多线程的 不能使用ArrayList要使用Vector 这样才安全   非线程安全并不是多线程环境下就不能使用 注意我上面有说到 多线程操作同一个对象 注意是同一个对象 比如最上面那个模拟 就是在主线程中new的一个ArrayList然后多个线程操作同一个ArrayList对象   如果是每个线程中new一个ArrayList 而这个ArrayList只在这一个线程中使用 那么肯定是没问题的   线程安全的实现   线程安全是通过线程同步控制来实现的 也就是synchronized关键字   在这里 我用代码分别实现了一个非线程安全的计数器和线程安全的计数器Counter 并对他们分别进行了多线程测试   非线程安全的计数器   [java]   public class Main   {   public static void main(String[] args)   {   // 进行 次测试   for(int i = ; i < ; i++)   {   test();   }   }   public static void test()   {   // 计数器   Counter counter = new Counter();   // 线程数量( )   int threadCount = ;   // 用来让主线程等待threadCount个子线程执行完毕   CountDownLatch countDownLatch = new CountDownLatch(threadCount);   // 启动threadCount个子线程   for(int i = ; i < threadCount; i++)   {   Thread thread = new Thread(new MyThread(counter countDownLatch));   thread start();   }   try   {   // 主线程等待所有子线程执行完成 再向下执行   countDownLatch await();   }   catch (InterruptedException e)   {   e printStackTrace();   }   // 计数器的值   System out println(counter getCount());   }   }   class MyThread implements Runnable   {   private Counter counter;   private CountDownLatch countDownLatch;   public MyThread(Counter counter CountDownLatch countDownLatch)   {   unter = counter;   untDownLatch = countDownLatch;   }   public void run()   {   // 每个线程向Counter中进行 次累加   for(int i = ; i < ; i++)   {   counter addCount();   }   // 完成一个子线程   untDown();   }   }   class Counter   {   private int count = ;   public int getCount()   {   return count;   }   public void addCount()   {   count++;   }   }   public class Main   {   public static void main(String[] args)   {   // 进行 次测试   for(int i = ; i < ; i++)   {   test();   }   }   public static void test()   {   // 计数器   Counter counter = new Counter();   // 线程数量( )   int threadCount = ;   // 用来让主线程等待threadCount个子线程执行完毕   CountDownLatch countDownLatch = new CountDownLatch(threadCount);   // 启动threadCount个子线程   for(int i = ; i < threadCount; i++)   {   Thread thread = new Thread(new MyThread(counter countDownLatch));   thread start();   }   try   {   // 主线程等待所有子线程执行完成 再向下执行   countDownLatch await();   }   catch (InterruptedException e)   {   e printStackTrace();   }   // 计数器的值   System out println(counter getCount());   }   }   class MyThread implements Runnable   {   private Counter counter;   private CountDownLatch countDownLatch;   public MyThread(Counter counter CountDownLatch countDownLatch)   {   unter = counter;   untDownLatch = countDownLatch;   }   public void run()   {   // 每个线程向Counter中进行 次累加   for(int i = ; i < ; i++)   {   counter addCount();   }   // 完成一个子线程   untDown();   }   }   class Counter   {   private int count = ;   public int getCount()   {   return count;   }   public void addCount()   {   count++;   }   }   上面的测试代码中 开启 个线程 每个线程对计数器进行 次累加 最终输出结果应该是   但是上面代码中的Counter未进行同步控制 所以非线程安全   输出结果                                 稍加修改 把Counter改成线程安全的计数器   [java]   class Counter   {   private int count = ;   public int getCount()   {   return count;   }   public synchronized void addCount()   {   count++;   }   }   class Counter   {   private int count = ;   public int getCount()   {   return count;   }   public synchronized void addCount()   {   count++;   }   }   上面只是在addCount()方法中加上了synchronized同步控制 就成为一个线程安全的计数器了 再执行程序   输出结果                            lishixinzhi/Article/program/Java/gj/201311/27519
2023-07-24 20:06:321

SpringBoot整合Redisson

Redisson的Github地址: https://github.com/redisson/redisson/wiki/Table-of-Content 基于Redis的Redisson分布式可重入锁RLock对象实现了java.util.concurrent.locks.Lock接口。 大家都知道,如果负责储存这个分布式锁的Redisson节点宕机以后,而且这个锁正好处于锁住的状态时,这个锁会出现锁死的状态。为了避免这种情况的发生,Redisson内部提供了一个 监控锁的看门狗 ,它的作用是在Redisson实例被关闭前,不断的延长锁的有效期。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。 在RedissonLock类的renewExpiration()方法中,会启动一个定时任务每隔30/3=10秒给锁续期。如果业务执行期间,应用挂了,那么不会自动续期,到过期时间之后,锁会自动释放。 另外Redisson还提供了leaseTime的参数来指定加锁的时间。超过这个时间后锁便自动解开了。 如果指定了锁的超时时间,底层直接调用lua脚本,进行占锁。如果超过leaseTime,业务逻辑还没有执行完成,则直接释放锁,所以在指定leaseTime时,要让leaseTime大于业务执行时间。RedissonLock类的tryLockInnerAsync()方法 分布式可重入读写锁允许同时有多个读锁和一个写锁处于加锁状态。在读写锁中,读读共享、读写互斥、写写互斥。 读写锁测试类,当访问write接口时,read接口会被阻塞住。 Redisson的分布式信号量与的用法与java.util.concurrent.Semaphore相似 现在redis中保存semaphore的值为3 然后在TestController中添加测试方法: 当访问acquireSemaphore接口时,redis中的semaphore会减1;访问releaseSemaphore接口时,redis中的semaphore会加1。当redis中的semaphore为0时,继续访问acquireSemaphore接口,会被阻塞,直到访问releaseSemaphore接口,使得semaphore>0,acquireSemaphore才会继续执行。 CountDownLatch作用:某一线程,等待其他线程执行完毕之后,自己再继续执行。 在TestController中添加测试方法,访问close接口时,调用await()方法进入阻塞状态,直到有三次访问release接口时,close接口才会返回。
2023-07-24 20:07:111

java 静态内部匿名类中为什么可以应用this关键字,且引用的this指代什么?

1、当在匿名类中用this时,这个this则指的是匿名类或内部类本身。2、this.i=i 是指 当成员变量和局部变量重名时,在方法中使用this时,表示的是该方法所在类中的成员变量。(this是当前对象自己)
2023-07-24 20:07:191

Java 怎么在Main函数中,执行完异步任务后才退出主线程

你能说下目的吗。可以加个navtice变量,子线程完成后设为true, 主线程加个while循环,当这个变更为true时,结束循环,也就自动结束了
2023-07-24 20:07:283

java如何在多线程执行完后才执行其他任务

设置一个计数器,每个线程执行完后计数器加一然后查看计数器是否已满(任务都完成),没有的话就阻塞,是的话就唤醒其他所有线程,大家一起来执行下一次任务。要注意公用的计数器的线程安全!
2023-07-24 20:08:334

C# 如何控制子线程运行结束后再运行主线程

java 有一个CountDownLatch类,是专门处理这种问题的。.net好像没有这样的类,你搜一下.net CountDownLatch,然后会出现模拟这个类的一些代码。原理基本上就是一开始定义一个CountDownLatch计数器,比如你有两个子线程,那么这个计数器就为2,然后每个子线程执行完之后,计数器-1,直到到0位置,两个子线程外面需要用 await()方法来阻塞,这样当计数器为0的时候,主线程就能继续执行了。我在java里写的代码,你可以参照网上的例子模拟一个CountDownLatch类。final CountDownLatch lock = new CountDownLatch(1);//验证文件服务器是否运行是否正常new Thread(new Runnable() { public void run() { startCheck(lock); } }).start();lock.await();等待//主线程继续执行startCheck方法里边如果执行完了之后,只需要调用lock.countDown();就行了。
2023-07-24 20:09:562

httpasyncclient异步提交post时,运行2分钟就变得很慢,该怎么解决

public static void main(String[] args) throws Exception { ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(); PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(ioReactor); cm.setMaxTotal(100); CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.custom().setConnectionManager(cm).build(); httpAsyncClient.start(); String[] urisToGet = { "http://www.chinaso.com/", "http://www.so.com/", "http://www.qq.com/", }; final CountDownLatch latch = new CountDownLatch(urisToGet.length); for (final String uri: urisToGet) { final HttpGet httpget = new HttpGet(uri); httpAsyncClient.execute(httpget, new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { latch.countDown(); System.out.println(httpget.getRequestLine() + "->" + response.getStatusLine()); } public void failed(final Exception ex) { latch.countDown(); System.out.println(httpget.getRequestLine() + "->" + ex); } public void cancelled() { latch.countDown(); System.out.println(httpget.getRequestLine() + " cancelled"); } }); } latch.await();
2023-07-24 20:10:042

快速学习jav的方法有哪些?

学习没有捷径,但要有好的方法提高效率
2023-07-24 20:10:132

jdk1.7和jdk1.8区别

1、jdk1.8广义上来说,可以说是1.7的增强版,即1.8的功能更加强大,如:1.8中Switch语句支持string类型 、 Try-with-resource语句 、5 数字类型的下划线表示 更友好的表示方式、在可变参数方法中传递非具体化参数,改进编译警告和错误 ;这个太多了,2、 需要注意的是,你用1.8版本开发的程序如果换到其余的1.7版本下可能会报错,即无法运行,而1.7版本下开发的程序,在1.8版本下应该可以正常的运行。 因为版本是自上而下兼容,而自下而上,可能会出问题3、所以建议在真正的开发过程中建议使用1.6或1.7版本(1.8还不是很普遍)
2023-07-24 20:10:234

如何解决java接口访问ZooKeeper时的connectionloss错误

常见错误日志如下:org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss1. 原因:是因为ZooKeeper建立连接时采用异步操作,连接操作后并不能保证ZK连接已成功。如果在ZK连接成功前的这个小时间窗口去访问ZK,就会碰到如上错误。2. 解决思路我们在新建ZK连接后要等一段时间,保证连接成功后再访问ZK。3. 网上比较赞同的解决方案:主要利用两个Java类:(1)java.util.concurrent.CountDownLatch:一个同步辅助类,类似倒数计数,直到计数器为0时才能对资源“解锁”。未解锁前等待该资源的进程只能被阻塞。主要方法:public CountDownLatch(int count); /* 构造函数,参数指定计数次数 */public void countDown(); /* 当前线程调用此函数,则计数减一 */public void await() throws InterruptedException; /* 此函数会一直阻塞当前线程,直到计时器的值为0为止 */(2)org.apache.zookeeper.WatcherZooKeeper有一个很有用的功能,就是集群上每一个变化都可以通知到自定义的Watchcer。
2023-07-24 20:10:401

Java 怎么在Main函数中,执行完异步任务后才退出主线程

你能说下目的吗。可以加个navtice变量,子线程完成后设为true,主线程加个while循环,当这个变更为true时,结束循环,也就自动结束了
2023-07-24 20:10:472

5种方法,教你判断线程池是否全部完成

最近写小玩具的时候用到了 CountDownLatch 计数器,然后顺便想了想判断线程池全部结束有多少种方法。 在网上搜了下,可能有些没找到,但是我找到的有(所有方法都是在 ThreadPoolExecutor 线程池方法下测试的): 好嘞,现在开始一个一个介绍优缺点和简要原理; 先创建一个 static 线程池,后面好几个例子就不一一创建了,全部用这个就行了: 然后再准备一个通用的睡眠方法: 这个方法就是为了测试的时候区分线程执行完毕的下顺序而已。 好嘞,准备完毕,现在开始。 首先贴上测试代码: 这一种方式就是在主线程中进行循环判断,全部任务是否已经完成。 这里有两个主要方法: 通俗点讲,就是在执行全部任务后,对线程池进行 shutdown() 有序关闭,然后循环判断 isTerminated() ,线程池是否全部完成。 类似方法扩展: 还是一样,贴上代码: 还是一样在主线程循环判断,主要就两个方法: 这个好理解,总任务数等于已完成任务数,就表示全部执行完毕。 其他 : 最后扯两句,因为我用 main 方法运行的,跑完后 main 没有结束,是因为非守护线程如果不终止,程序是不会结束的。而线程池 Worker 线程里写了一个死循环,而且被设置成了非守护线程。 这种方法是我比较常用的方法,先看代码: 这种方法,呃,应该是看起来比较高级的,我也不知道别的大佬怎么写的,反正我就用这个。 这个方法需要介绍下这个工具类 CountDownLatch 。先把这种方式的优缺点写了,后面再详细介绍这个类。 CountDownLatch 是 JDK 提供的一个同步工具,它可以让一个或多个线程等待,一直等到其他线程中执行完成一组操作。 常用的方法有 countDown 方法和 await 方法, CountDownLatch 在初始化时,需要指定用给定一个整数作为计数器。 当调用 countDown 方法时,计数器会被减1;当调用 await 方法时,如果计数器大于0时,线程会被阻塞,一直到计数器被 countDown 方法减到0时,线程才会继续执行。 计数器是无法重置的,当计数器被减到0时,调用 await 方法都会直接返回。 这种方式其实和 CountDownLatch 原理类似。 先维护一个静态变量 然后在线程任务结束时,进行静态变量操作: 其实就是加锁计数,循环判断。 Future 是用来装载线程结果的,不过,用这个来进行判断写代码总感觉怪怪的。 因为 Future 只能装载一条线程的返回结果,多条线程总不能用 List 在接收 Future 。 这里就开一个线程做个演示: 这种方式就不写优缺点了,因为 Future 的主要使用场景并不是用于判断任务执行状态。
2023-07-24 20:10:541

java多线程模拟多用户同时查询数据库,计算查询时间。为什么线程跑完后,执行不到t2这部来,无异常显示。

t2这部分不会被运行了countDownLatch 根本就没有执行过countDown的调用你可以首先把countDown变成类的静态成员变量,或者把countDown作为参数带入到类Calc 中,在run方法结束的时候执行countDownLatch.countDown();如果不执行countDownLatch.countDown();操作,计数器不会产生变化,线程跑完了以后程序就停在countDownLatch.await(); 傻等着了........
2023-07-24 20:11:011

怎么在main方法里中断其他线程

要实现这个情况,必须知道以下几点1、java中线程的结束是由run方法运行完成后自动结束的2、在main线程(主线程)中,需要得到所有线程的引用。3、知道jdk提供的CountDownLatch的用法例子如下:public static void main(String[] args) throws InterruptedException {//CountDownLatch作为计数器纪录有几个线程,例如有2个线程CountDownLatch latch=new CountDownLatch(2);Worker worker1=new Worker( latch);Worker worker2=new Worker(latch);worker1.start();// 启动线程worker2.start();////等待所有工人完成工作latch.await();System.out.println("all work done at "+sdf.format(new Date()));} class Worker extends Thread{private CountDownLatch latch;public Worker(CountDownLatch latch){this.latch = latch;}public void run(){xxxxx//在run方法结束之前,讲线程计数器减一latch.countDown();}}
2023-07-24 20:11:201

如何等待java线程池中所有任务完成

用java.util.concurrent下面的类实现线程池就可以
2023-07-24 20:11:281

如何确保main()方法所在的线程是Java程序最后结束的线程?

可以使用Thread类的joint()方法来确保所有程序创建的线程在main()方法退出前结束。可以多了解一些关于Thread类的joint()方法。
2023-07-24 20:11:372

java countdownlatch可以重复使用吗

是线程安全的,这个类设计的目的就是多线程直接的同步合作。试想,如果它不是线程安全的,那岂不是错误的实现~无论有几个线程在操作countdownlatch实例,调用countdownlatch.await()的线程A会被阻塞,除非其他线程BCD...调用countdownlatch.countdown()并且计数器至0.你可以参考这个回答:
2023-07-24 20:11:441

Java中的main线程是不是最后一个退出的线程

这未必的~~~
2023-07-24 20:11:522

main线程结束,子线程为什么没有退出

要实现这个情况,必须知道以下几点1、java中线程的结束是由run方法运行完成后自动结束的2、在main线程(主线程)中,需要得到所有线程的引用。3、知道jdk提供的CountDownLatch的用法例子如下:public static void main(String[] args) throws InterruptedException { //CountDownLatch作为计数器纪录有几个线程,例如有2个线程CountDownLatch latch=new CountDownLatch(2);Worker worker1=new Worker( latch); Worker worker2=new Worker(latch); worker1.start();// 启动线程worker2.start();// //等待所有工人完成工作 latch.await();System.out.println("all work done at "+sdf.format(new Date())); } class Worker extends Thread{private CountDownLatch latch;public Worker(CountDownLatch latch){this.latch = latch;}public void run(){xxxxx//在run方法结束之前,讲线程计数器减一latch.countDown();}}
2023-07-24 20:11:591

java 中有两个线程怎样等待一个线程执行完毕

观公孙大娘弟子舞剑器行(杜甫)[6]
2023-07-24 20:12:063

java如何在多线程执行完成后再执行某个方法

java.util.concurrent.CountDownLatch 这个类可以实现你所要的功能例如:CountDownLatch latch = new CountDownLatch(5) //声明计数器为5个Thread t = new Thread() {public void run() {try {//TODO 你的应用} catch (Exception e) {//TODO 异常处理}finally {latch.countDown(); //这句是关键System.out.println("ok"); //5个线程都跑完后输出}}};t.start();然后让以上操作循环五次(就是说同时开5个线程),那么这个"ok"就会在等到这5个线程都ok后才会被输出一次。
2023-07-24 20:12:281

如何在Main函数中,执行完异步任务后才退出主线程

要实现这个情况,必须知道以下几点1、java中线程的结束是由run方法运行完成后自动结束的2、在main线程(主线程)中,需要得到所有线程的引用。3、知道jdk提供的CountDownLatch的用法例子如下:public static void main(String[] args) throws InterruptedException { //CountDownLatch作为计数器纪录有几个线程,例如有2个线程CountDownLatch latch=new CountDownLatch(2);Worker worker1=new Worker( latch); Worker worker2=new Worker(latch); worker1.start();// 启动线程worker2.start();// //等待所有工人完成工作 latch.await();System.out.println("all work done at "+sdf.format(new Date())); } class Worker extends Thread{private CountDownLatch latch;public Worker(CountDownLatch latch){this.latch = latch;}public void run(){xxxxx//在run方法结束之前,讲线程计数器减一latch.countDown();}}
2023-07-24 20:12:351

如何解决java接口访问ZooKeeper时的connectionloss错误

常见错误日志如下:org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss1. 原因:是因为ZooKeeper建立连接时采用异步操作,连接操作后并不能保证ZK连接已成功。如果在ZK连接成功前的这个小时间窗口去访问ZK,就会碰到如上错误。2. 解决思路我们在新建ZK连接后要等一段时间,保证连接成功后再访问ZK。3. 网上比较赞同的解决方案: 主要利用两个Java类: (1)java.util.concurrent.CountDownLatch: 一个同步辅助类,类似倒数计数,直到计数器为0时才能对资源“解锁”。未解锁前等待该资源的进程只能被阻塞。 主要方法: public CountDownLatch(int count); /* 构造函数,参数指定计数次数 */ public void countDown(); /* 当前线程调用此函数,则计数减一 */ public void await() throws InterruptedException; /* 此函数会一直阻塞当前线程,直到计时器的值为0为止 */ (2)org.apache.zookeeper.Watcher ZooKeeper有一个很有用的功能,就是集群上每一个变化都可以通知到自定义的Watchcer。
2023-07-24 20:12:421

AQS共享锁和独占锁

本文使用 ReentrantLock 和 CountDownLatch 演示独占锁和共享锁的实现。 独占锁 获取锁 释放锁 共享锁 通过status标识锁 ReentrantLock使用排他锁。AQS的status>0表示加锁,thread是当前获取锁的线程。该锁时可重入锁,所以status>0。 CountDownLatch 使用共享锁。AQS的status为共享锁的标记位,status>0就是加锁,等于0就是释放锁。每调用一次countDown(),status减1。 线程会阻塞在await(),直到countDown()将status置为0
2023-07-24 20:12:511

java主线程无线循环判断为什么要sleep?

你可以百度搜一下sleep(0),道理一样
2023-07-24 20:13:008

如何实现java主线程等待子线程执行完毕之后再执行

java.util.concurrent.CountDownLatch 这个类可以实现你所要的功能例如:CountDownLatch latch = new CountDownLatch(5) //声明计数器为5个Thread t = new Thread() {public void run() {try {//TODO 你的应用} catch (Exception e) {//TODO 异常处理}finally {latch.countDown(); //这句是关键System.out.println("ok"); //5个线程都跑完后输出}}};t.start();然后让以上操作循环五次(就是说同时开5个线程),那么这个"ok"就会在等到这5个线程都ok后才会被输出一次。
2023-07-24 20:13:171

JAVA里有没有类似SLEEP的函数

2023-07-24 20:13:241

java来调和线程轮询的区别

可以使用CountDownLatch, 设定线程数量,然后在每个线程完成的是,latch.countDown()在轮询主线程中使用latch.await(), 这个函数会等待所有线程执行完成后继续允许,即你在轮询前记录一个时间,latch.await() 后面记录完成时间
2023-07-24 20:13:491

c++请求netty为什么没反应

public class SyncFuture<T> implements Future<T> { // 因为请求和响应是一一对应的,因此初始化CountDownLatch值为1。 private CountDownLatch latch = new CountDownLatch(1); // 需要响应线程设置的响应结果 private T response; // Futrue的请求时间,用于计算Future是否超时 private long beginTime = System.currentTimeMillis(); public SyncFuture() { } @Override public boolean cancel(boolean mayInterruptIfRunning) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { if (response != null) { return true; } return false; } // 获取响应结果,直到有结果才返回。 @Override public T get() throws InterruptedException { latch.await(); return this.response; } // 获取响应结果,直到有结果或者超过指定时间就返回。 @Override public T get(long timeout, TimeUnit unit) throws InterruptedException { if (latch.await(timeout, unit)) { return this.response; } return null; } // 用于设置响应结果,并且做countDown操作,通知请求线程 public void setResponse(T response) { this.response = response; latch.countDown(); } public long getBeginTime() { return beginTime; }}
2023-07-24 20:13:571

调用test方法 只需要3毫秒 而是用现成去执行 有时候 要需要 5毫秒,用多线程去执行 不是应该更快吗?

多线程,并不能使一个方法执行得更快,只是可以“并发”让多个任务同步干活,是整体上快了。
2023-07-24 20:14:041

sparkstreaming结果可以直接flume汇总吗

首先,需要将以下代码编译成jar包,然后在flume中使用,代码转自这里 (如果发现需要依赖的工具类神马的,请在相同目录下的scala文件中找一找) package org.apache.spark.streaming.flume.sinkimport java.net.InetSocketAddressimport java.util.concurrent._import org.apache.avro.ipc.NettyServerimport org.apache.avro.ipc.specific.SpecificResponderimport org.apache.flume.Contextimport org.apache.flume.Sink.Statusimport org.apache.flume.conf.{Configurable, ConfigurationException}import org.apache.flume.sink.AbstractSink/** * A sink that uses Avro RPC to run a server that can be polled by Spark"s * FlumePollingInputDStream. This sink has the following configuration parameters: * * hostname - The hostname to bind to. Default: 0.0.0.0 * port - The port to bind to. (No default - mandatory) * timeout - Time in seconds after which a transaction is rolled back, * if an ACK is not received from Spark within that time * threads - Number of threads to use to receive requests from Spark (Default: 10) * * This sink is unlike other Flume sinks in the sense that it does not push data, * instead the process method in this sink simply blocks the SinkRunner the first time it is * called. This sink starts up an Avro IPC server that uses the SparkFlumeProtocol. * * Each time a getEventBatch call comes, creates a transaction and reads events * from the channel. When enough events are read, the events are sent to the Spark receiver and * the thread itself is blocked and a reference to it saved off. * * When the ack for that batch is received, * the thread which created the transaction is is retrieved and it commits the transaction with the * channel from the same thread it was originally created in (since Flume transactions are * thread local). If a nack is received instead, the sink rolls back the transaction. If no ack * is received within the specified timeout, the transaction is rolled back too. If an ack comes * after that, it is simply ignored and the events get re-sent. * */class SparkSink extends AbstractSink with Logging with Configurable { // Size of the pool to use for holding transaction processors. private var poolSize: Integer = SparkSinkConfig.DEFAULT_THREADS // Timeout for each transaction. If spark does not respond in this much time, // rollback the transaction private var transactionTimeout = SparkSinkConfig.DEFAULT_TRANSACTION_TIMEOUT // Address info to bind on private var hostname: String = SparkSinkConfig.DEFAULT_HOSTNAME private var port: Int = 0 private var backOffInterval: Int = 200 // Handle to the server private var serverOpt: Option[NettyServer] = None // The handler that handles the callback from Avro private var handler: Option[SparkAvroCallbackHandler] = None // Latch that blocks off the Flume framework from wasting 1 thread. private val blockingLatch = new CountDownLatch(1) override def start() { logInfo("Starting Spark Sink: " + getName + " on port: " + port + " and interface: " + hostname + " with " + "pool size: " + poolSize + " and transaction timeout: " + transactionTimeout + ".") handler = Option(new SparkAvroCallbackHandler(poolSize, getChannel, transactionTimeout, backOffInterval)) val responder = new SpecificResponder(classOf[SparkFlumeProtocol], handler.get) // Using the constructor that takes specific thread-pools requires bringing in netty // dependencies which are being excluded in the build. In practice, // Netty dependencies are already available on the JVM as Flume would have pulled them in. serverOpt = Option(new NettyServer(responder, new InetSocketAddress(hostname, port))) serverOpt.foreach(server => { logInfo("Starting Avro server for sink: " + getName) server.start() }) super.start() } override def stop() { logInfo("Stopping Spark Sink: " + getName) handler.foreach(callbackHandler => { callbackHandler.shutdown() }) serverOpt.foreach(server => { logInfo("Stopping Avro Server for sink: " + getName) server.close() server.join() }) blockingLatch.countDown() super.stop() } override def configure(ctx: Context) { import SparkSinkConfig._ hostname = ctx.getString(CONF_HOSTNAME, DEFAULT_HOSTNAME) port = Option(ctx.getInteger(CONF_PORT)). getOrElse(throw new ConfigurationException("The port to bind to must be specified")) poolSize = ctx.getInteger(THREADS, DEFAULT_THREADS) transactionTimeout = ctx.getInteger(CONF_TRANSACTION_TIMEOUT, DEFAULT_TRANSACTION_TIMEOUT) backOffInterval = ctx.getInteger(CONF_BACKOFF_INTERVAL, DEFAULT_BACKOFF_INTERVAL) logInfo("Configured Spark Sink with hostname: " + hostname + ", port: " + port + ", " + "poolSize: " + poolSize + ", transactionTimeout: " + transactionTimeout + ", " + "backoffInterval: " + backOffInterval) } override def process(): Status = { // This method is called in a loop by the Flume framework - block it until the sink is // stopped to save CPU resources. The sink runner will interrupt this thread when the sink is // being shut down. logInfo("Blocking Sink Runner, sink will continue to run..") blockingLatch.await() Status.BACKOFF } private[flume] def getPort(): Int = { serverOpt .map(_.getPort) .getOrElse( throw new RuntimeException("Server was not started!") ) } /** * Pass in a [[CountDownLatch]] for testing purposes. This batch is counted down when each * batch is received. The test can simply call await on this latch till the expected number of * batches are received. * @param latch */ private[flume] def countdownWhenBatchReceived(latch: CountDownLatch) { handler.foreach(_.countDownWhenBatchAcked(latch)) }}/** * Configuration parameters and their defaults. */private[flume]object SparkSinkConfig { val THREADS = "threads" val DEFAULT_THREADS = 10 val CONF_TRANSACTION_TIMEOUT = "timeout" val DEFAULT_TRANSACTION_TIMEOUT = 60 val CONF_HOSTNAME = "hostname" val DEFAULT_HOSTNAME = "0.0.0.0" val CONF_PORT = "port" val CONF_BACKOFF_INTERVAL = "backoffInterval" val DEFAULT_BACKOFF_INTERVAL = 200}   然后在你的streaming中使用如下的代码package org.apache.spark.examples.streaming import org.apache.spark.SparkConfimport org.apache.spark.storage.StorageLevelimport org.apache.spark.streaming._import org.apache.spark.streaming.flume._import org.apache.spark.util.IntParamimport java.net.InetSocketAddress/** * Produces a count of events received from Flume. * * This should be used in conjunction with the Spark Sink running in a Flume agent. See * the Spark Streaming programming guide for more details. * * Usage: FlumePollingEventCount <host> <port> * `host` is the host on which the Spark Sink is running. * `port` is the port at which the Spark Sink is listening. * * To run this example: * `$ bin/run-example org.apache.spark.examples.streaming.FlumePollingEventCount [host] [port] ` */object FlumePollingEventCount { def main(args: Array[String]) { if (args.length < 2) { System.err.println( "Usage: FlumePollingEventCount <host> <port>") System.exit(1) } StreamingExamples.setStreamingLogLevels() val Array(host, IntParam(port)) = args val batchInterval = Milliseconds(2000) // Create the context and set the batch size val sparkConf = new SparkConf().setAppName("FlumePollingEventCount") val ssc = new StreamingContext(sparkConf, batchInterval) // Create a flume stream that polls the Spark Sink running in a Flume agent val stream = FlumeUtils.createPollingStream(ssc, host, port) // Print out the count of events received from this server in each batch stream.count().map(cnt => "Received " + cnt + " flume events." ).print() ssc.start() ssc.awaitTermination() }}
2023-07-24 20:14:131

如何计算 java 轮询线程消耗

可以使用CountDownLatch, 设定线程数量,然后在每个线程完成的是,latch.countDown()在轮询主线程中使用latch.await(), 这个函数会等待所有线程执行完成后继续允许,即你在轮询前记录一个时间,latch.await() 后面记录完成时间
2023-07-24 20:14:561

android countdownlatch能控制主线程吗

oncurrent包里面的CountDownLatch其实可以把它看作一个计数器,只不过这个计数器的操作是原子操作,同时只能有一个线程去操作这个计数器,也就是同时只能有一个线程去减这个计数器里面的值。 CountDownLatch的一个非常典型的应用场景是:有一个任务想要往下执行,但必须要等到其他的任务执行完毕后才可以继续往下执行。假如我们这个想要继续往下执行的任务调用一个CountDownLatch对象的await()方法,其他的任务执行完自己的任务后调用同一个CountDownLatch对象上的countDown()方法,这个调用await()方法的任务将一直阻塞等待,直到这个CountDownLatch对象的计数值减到0为止。
2023-07-24 20:15:151

java 多线程为什么顺序执行

5个人去上厕所,一个个接着进去,每个人都要蹲一分钟才能拉出来,那你说谁会先拉出来?
2023-07-24 20:15:292

java问题 有一个list有1W条数据, 现在我想用多线程不重复的读取list中的数据,要怎么写?

@Slf4jpublic class FixedThreadPool {/** 请求总数**/private static int clientTotal = 100;public static AtomicInteger atomicInteger = new AtomicInteger(0);public static void main(String[] args) throws Exception {ExecutorService executorService = Executors.newFixedThreadPool(10);final CountDownLatch countDownLatch = new CountDownLatch(clientTotal);for (int i = 0; i < clientTotal; i++) { //这里clientTotal你换成你的list的sizeatomicInteger.incrementAndGet();while (atomicInteger.get() > 4){Thread.sleep(10);}executorService.execute(() -> {consoleLog();countDownLatch.countDown();atomicInteger.decrementAndGet();});}countDownLatch.await();executorService.shutdown();log.info("全部执行完毕");}private static void consoleLog(){try {log.info("hello");Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}}}
2023-07-24 20:15:493

java 怎么在一个线程对象访问某类的时候 追加一个任务在其执行完之后执行?

java.util.concurrent.CountDownLatch 这个类可以实现你所要的功能例如:CountDownLatch latch = new CountDownLatch(5) //声明计数器为5个Thread t = new Thread() {public void run() {try {//TODO 你的应用} catch (Exception e) {//TODO 异常处理}finally {latch.countDown(); //这句是关键System.out.println("ok"); //5个线程都跑完后输出}}};t.start();然后让以上操作循环五次(就是说同时开5个线程),那么这个"ok"就会在等到这5个线程都ok后才会被输出一次。
2023-07-24 20:15:571

mac下webstorm占用内存和cpu都太多,导致特别卡,怎么解决

卸载,说明你的配置太低了
2023-07-24 20:06:542

我要个英文名

SAM
2023-07-24 20:06:564

呢组词 呢字怎么组词

U0001f478U0001f482U0001f47eU0001f481U0001f491U0001f48fU0001f48bU0001f485U0001f44dU0001f64cU0001f645U0001f47cU0001f385U0001f646U0001f44fU0001f44dU0001f44eU0001f442U0001f486U0001f47bU0001f4a9U0001f487U0001f440U0001f446U0001f447U0001f443U0001f64bU0001f480U0001f47dU0001f647U0001f444
2023-07-24 20:06:566

vacuum和cacuum的区别

请问cacuum是什么词?是不是打错了?我没有查到这个词
2023-07-24 20:06:583

如何在WebStorm 2017下调试Vue.js + webpack

有人觉得vue项目难调试,是因为用了webpack。所有代码揉在了一起,还加了很多框架代码,根本不知道怎么下手。所以vue+webpack调试要从webpack入手。1.我们先从一般情况开始说。-sourcemapwebpack配置提供了devtool这个选项,如果设置为 ‘#source-map",则可以生成.map文件,在chrome浏览器中调试的时候可以显示源代码。devtool: "#source-map"2.然而这个设置实际上没这么简单。webpack官方给出了7个配置项供选择: 01.devtool介绍这里不同的配置有些不同的效果,比如是否保留注释、保留行信息等,具体每一条什么意思这里不详解释,有兴趣的童鞋可以参考这篇文章官方默认的是用 ‘#cheap-module-eval-source-map"devtool: "#cheap-module-eval-source-map"设置好之后,在vue项目调试的时候,代码里面标注debugger的时候就能看到对应的代码了,非常方便。02.debugger或者,直接找到对应的文件。在chrome用 "ctrl(command) + p‘,输入文件名,可以找到对应的源代码。command+p打断点:断点需要注意的是,这里断点会打在下一行。同时一行代码运行在它的下一行才算执行。03.-vue-clivue家的项目脚手架,推荐使用。vue-cli老家在这里 vue-cli可以帮我们自动搭建项目,首先npm全局安装npm install -g vue-cli然后创建一个新的项目vue init webpack my-project一路回车,搞定。(更多配置项请参考上面给出的vue-cli链接)这里从网上下载了一个带webpack的vue项目(跑之前记得npm install一下) 04.vue-cli webpack 从bulid文件夹里面就大概能看出:u2022webpack.dev.conf: 开发模式用u2022webpack.prod.conf: 生产模式用其中,开发模式提供了devtool为"#cheap-module-eval-source-map",生产模式根据config文件夹下的productionSourceMap变量控制是否使用。若为true,则devtool为"#source-map"其他使用方法一致。非常方便。3.线上调试平时开发的时候,我们用webpack的热加载,可以省去挂载调试的步骤,非常方便。但是发布后部署到服务器上,就失去了这个本地优势。如果使用挂载文件方式会比较麻烦。由于webpack打出来的文件有版本号这些信息,而且发布一个包看代码量可能需要等待不等,这个方案不实际。但是如果挂载的是热加载到端口下的文件的话,这个问题就很好办了。-热加载在此之前,先来分析一下webpack的热加载原理。对项目抓包可以发现这么一个文件:__webpack_hmr__webpack_hmr这是webpack热加载的服务器推送事件,eventsource类型,功能和websocket有点类似。大致作用是建立一个不会停止的stream流链接,服务器发送更新数据回来append到流的末端,前端读取最新append的数据,然后动态的更新页面上的东西。接下来我们观察下上文提到的更新数据有哪些。随便更新一个文件,触发热加载,再抓个包,发现有两个.hot-update.json和一个.hot-update.js文件热加载更新文件这些具体做了些啥我不知道,这里就不深究了。应该是根据json里面的数据,达到一个准确更新的效果。所以热更新其实就是监听服务器上的数据,有修改的话服务器发送数据过来,前端把数据拿来后替换到页面上这么一个过程。-AutoResponder接下来谈谈线上挂载测试,这里推荐一款软件:fiddlerfiddler有一个功能叫做AutoResponder,它可以将一个地址指向另一个地址。之所以用这个软件,是因为它能匹配正则,非常方便。AutoResponder上一节说到,webpack热加载用到了这几类文件u2022__webpack_hmru2022xxxxxxxxxxx.hot-update.jsonu2022xxxxxxxxxxx.hot-update.js
2023-07-24 20:07:011

Vans鞋的后标只有Vans的是正品吗?(没有off the wall)是日版的吗?

2023-07-24 20:07:045

“jump off the wall”是什么意思?

jump-off-the-wall从墙上跳下来双语例句1. One of the kids was peeling plaster off the wall. 其中一个孩子在剥墙上的灰泥。来自柯林斯例句2. It can be done without following some absurd, off-the-wall investment strategy. 不用遵照那套荒唐愚蠢的投资策略也可以做到。来自柯林斯例句3. He picked the telephone off the wall bracket. 他从墙上的固定托架上摘下电话。来自柯林斯例句查看更多权威例句1. My leg would spasm and jump off the bed. 来自THETIMES2. Supposing he should die or jump off the wharf? 来自NEWYORKER3. Turn off the heat and set the pan aside. 来自BBC
2023-07-24 20:06:531

C编程中出现expected;怎么办?

这里定义的float型的变量,但是用”“ string给它赋值,当然错了编译器也已经指出了错误的行
2023-07-24 20:06:491

我想翻译老鹰乐队的Peaceful Easy Feeling歌词 怎么办?

  我喜欢你明亮的耳环搭在你皮肤上的样子,它们是如此的褐色  I like the way your sparkling earrings lay,against your skin, it"s so brown  而且我今晚想要和你在四周是数不清的星星的沙漠中缠绵  I wanna sleep with youin the desert tonightwith a billion stars all around  因为我有一种轻松平静的感觉知道你不会让我失望  "cause I gotta peaceful easy feeling and I know you won"t let me down"  因为我已经站在这里而且我发现很久以前一个女人原来可以这样让触动你的灵魂  "cause I"m already standing on the ground And I found out a long time ago what a woman can do to your soul  啊~但是她不管怎么也不能和你一起 你自己都不知道应该怎么走  Ah, but she can"t take you anyway You don"t already(怀疑是really) know how to go  因为我有一种轻松平静的感觉知道你不会让我失望  and I gotta peaceful, easy feeling and I know you won"t let me down  因为我已经站在这里  "cause I"m already standing on the ground  我感觉到我也许只是认为你是一个情人和一个朋友  I get this feeling I may know you as a lover and a friend  但是这个声音一直在我耳边低喃,告诉我我可能再也不能见到你  but this voice keeps whispering in my other ear,tells me I may never see you again  因为我有一种轻松平静的感觉知道你不会让我失望  "cause I get a peaceful, easy feelingand I know you won"t let me down  因为我已经站在这里  "cause I"m already standing on the ground  因为我已经站起来了  "cause I"m already standing  0 。0 这个歌词在写什么 0 。0  为毛我翻译了一遍还是没看懂。  果然不喜欢这种男男女女的歌词。。  还有我翻译有很多不准的地方 不好意思
2023-07-24 20:06:471

webstorm和dreamweaver哪个好?哪个大一些

比dw强大的地方有:1. 对js的开发有长足的支持,那些自动提示,代码主题,调试之类的我就不说了,主要是对流行技术的支持,比如Node.js,less,sass,jq,ext,prototype等框架的支持 。2. 自身对插件的支持,主要体现在webstorm 2.0以后就已经包涵了zencoding了,而如果dw不是完整版的话,zencoding的安装难度可想而知。如果是完整版的话,就不得不忍受一坨无用的插件。3. 团队开发的支持,主要体现在svn,git等版本管理工具,无须引入,直接可用。而且单文件还支持本地历史记录。4. 插件的支持,主要体现在vim,可直接安装插件,还有其它的插件等待着你去挖掘。dw比webstorm的优点,那就是dw的内存占用大概平常80M左右,而webstorm得300M左右,这是我发现唯一dw的长处。如果说,dw是美工偶尔拖拖表格,写写css的小工具的话,那么webstorm是前端开发的必备利器,不只是对html,css的抒写比较强悍,而且对js,jq等其它js框架开发更是完美。简单的说:dw就是一个编辑器,而webstorm是一个IDE。另外一个,dw自从cs4之后,就已经无路可走,本来近几年的js开发如火如荼,看看这帮2B在dw cs5里边添加的那些隔靴搔痒的新功能,想想都笑,用户在不断的成长,市场在不断的变化,而这帮2B还在沉睡,残酷的市场如金的岁月会检验具有竞争力的产品。相比于dw的固步自封,webstorm正在走上坡路。这里不得不提一下另外一款:aptana ,本身在js方面有一定的靓点,可惜现在搞得跟dw一样,没有抓住现下流行的趋势,一直吃老本。看看aptana 3.0那些2B的功能,就能原谅dw现在还是这个样子。当然一分为二的看的话:如果你只是想拖拖表格,搞搞css,dw cs4 是目前市场上比较适合的编辑器。他的html结构自动识别折叠,能很快找到不完整的div,ctrl + d,跳到定义的class位置等等,是其它编辑器所没有的,在加上zencoding的话,写写静态页面足矣!如果你不只是想折腾css,而是想捣鼓捣鼓js,less,sass,node.js等等之类的新玩意,也想试试vim结合传统编辑器的威力,那webstorm绝对是你最佳的选择。如果你是phper,我推荐phpstorm,它包含所有webstorm的功能。
2023-07-24 20:06:461

迈迈off the wall歌词

off the wall1st verseWhen the world is on your shoulderGotta straighten up your act and boogie downIf you cant hang with the feelingThen there aint no room for you this part of towncause were the party people night and dayLivin crazy thats the only wayChorusSo tonight gotta leave that nine to five upon the shelfAnd just enjoy yourselfGroove, let the madness in the music get to youLife aint so bad at allIf you live it off the wallLife aint so bad at all (live life off the wall)Live your life off the wall (live it off the wall)2nd verseYou can shout out all you want tocause there aint no sin in folks all getting loudIf you take the chance and do itThen there aint no one whos gonna put you downcause were the party people night and dayLivin crazy thats the only wayChorusSo tonight gotta leave that nine to five upon the shelfAnd just enjoy yourselfCmon and groove, and let the madness in the music get to youLife aint so bad at allIf you live it off the wallLife aint so bad at all (live life off the wall)Live your life off the wall (live it off the wall)BridgeDo what you want to doThere aint no rules its up to you (aint no rules its all up to you)Its time to come aliveAnd party on right through the night (all right)3rd verseGotta hide your inhibitionsGotta let that fool loose deep inside your soulWant to see an exhibitionBetter do it now before you get to oldcause were the party people night and dayLivin crazy thats the only wayChorusSo tonight gotta leave that nine to five upon the shelf and just enjoyyourselfCmon and groove (yeah) let the madness in the music get to youLife aint so bad at all if you live it off the wallLife aint so bad at all (live life off the wall)Live your life off the wall (live it off the wall)ChorusSo tonight gotta leave that nine to five upon the shelf and just enjoyyourselfCmon and groove (yeah) let the madness in the music get to youLife aint so bad at all if you live it off the wallLife aint so bad at all (live life off the wall)Live your life off the wall (live it off the wall)
2023-07-24 20:06:441

how long , how far是什么意思主要怎么用?

不懂
2023-07-24 20:06:449