小编Chr*_*ris的帖子

使用 DateTimeFormatter ofPattern 解析日期

我正在尝试使用 解析包含日期和时间的字符串java.time.format.DateTimeFormatter(我的最终目标是将此字符串中的日期转换为java.time.LocalDate)。

尝试解析日期时,我不断收到 DateTimeParseExceptions。有人可以帮忙吗?

日期的格式为“2015-07-14T11:42:12.000+01:00”。

DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss.SSSZ");
LocalDateTime temp = LocalDateTime.ofInstant(Instant.from(f.parse(this.dateCreated)), 
                 ZoneId.systemDefault());
LocalDate localDate = temp.toLocalDate();
Run Code Online (Sandbox Code Playgroud)

我在 ofPattern 中尝试了不同的变体,例如尝试通过用单引号将 T 括起来(如上所述)来转义 T,并对 . 我试过同时逃避两者。

冒号也需要转义吗?

感谢您对此的任何帮助。

java parsing datetime-format date-parsing datetimeformatter

5
推荐指数
1
解决办法
2万
查看次数

与 maven surefire 插件并行运行测试

最近得到了一份新工作,我在做一个 Maven 和 Micronaut 项目——我是 Micronaut 的新手,如果你不熟悉,它是 Spring 的替代品。

以此为指导:https : //www.baeldung.com/maven-junit-parallel-tests

我试图让我们的集成测试并行运行,以加速我们的测试。我已将所需的配置添加到 pom.xml 文件中。我已经调整了很多,使用不同的设置组合(包括我在其他 SO 帖子中找到的设置)。

但是当我运行测试时,无论有没有添加这个配置,运行它们所需的时间都是一样的——1 分 38 秒。所以我认为它不起作用。虽然不知道我在控制台上的预期输出应该是什么样子,如果它正常工作?

在测试中,他们都没有使用@RunWith,它使用默认值,应该没问题。

这是pom。任何人都可以请指教吗?谢谢。

<profiles>
    <profile>
      <id>integration</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>unit, performance</excludedGroups>
              <parallel>classes</parallel>
              <threadCount>10</threadCount>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>performance</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>unit, integration</excludedGroups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>all</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>none</excludedGroups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
Run Code Online (Sandbox Code Playgroud)
<build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration> …
Run Code Online (Sandbox Code Playgroud)

java testing automated-tests maven-3 maven-surefire-plugin

5
推荐指数
1
解决办法
723
查看次数

量角器过滤器,如何在过滤元素中查找元素

下面是我的一些缩短的HTML,并尝试了一些量角器代码.

我正在尝试做的是点击一个i元素.我希望能够根据ID是什么来进行点击,这是一个兄弟元素.

以下代码不起作用.我也试过在过滤器中做一个过滤器,我尝试的一切都会导致错误.有人可以帮忙吗?我尝试这个尝试的错误是"无法读取未定义的属性元素.

有人可以帮忙吗?到目前为止,我已经花了很多时间!

谢谢.

element.all(by.repeater('data in ctrl.data')).filter(function(elem){
    return elem.element(by.css('div.case-info span')).getText() == id
}).then(function(filteredElements){
    filteredElements.first().element(by.css('i.fa')).click();
});




<div ng-repeater="data in ctrl.data">
    <div class="case-info">
        <span>AN ID HERE</span>
        <div>Other stuff here thats not really relevant</div>
    </div>
    <i class="fa fa-red"></i>
</div>
Run Code Online (Sandbox Code Playgroud)

angularjs protractor e2e-testing

3
推荐指数
1
解决办法
9149
查看次数

Java线程 - 死锁的解决方案?

我已经汇总了一些Java代码,它们演示了线程中的死锁.就它本身而言,我通常得到2行输出和一个异常,有时在输出行之前和有时之后是预期的.我得到的异常是transfer()方法第一行的NullPointerException.

我遇到的问题是我想知道如何解决这个死锁问题.我已经在StackOverflow上搜索了这个问题并找到了这个页面:

避免死锁示例

作为解决方案,我尝试过Will Hartung和Dreamcash发布的内容,但在尝试使用synchronize或ReentrantLock对象时仍然会遇到异常.

这是代码:

帐户类:

public class Account {

    int id;
    double balance;

    public Account(int id, double balance){
        this.id = id;
        this.balance = balance;
    }

    public void withdraw(double amount){
        balance = balance - amount;
    }

    public void deposit(double amount){
        balance = balance + amount;
    }

    public int getID(){
        return id;
    }

    public double getBalance(){
        return balance;
    }

}
Run Code Online (Sandbox Code Playgroud)

银行等级(单身人士):

public class Bank{

    static Bank bank;

    Account a1;
    Account a2;

    private Bank(){}

    public static Bank getInstance(){
        if(bank==null){
            bank = …
Run Code Online (Sandbox Code Playgroud)

java multithreading deadlock thread-safety

1
推荐指数
1
解决办法
1575
查看次数