小编And*_*302的帖子

为什么i ++不是原子的?

为什么i++Java中没有原子?

为了更深入地了解Java,我试图计算线程循环执行的频率.

所以我用了一个

private static int total = 0;
Run Code Online (Sandbox Code Playgroud)

在主要班级.

我有两个主题.

  • 线程1:打印 System.out.println("Hello from Thread 1!");
  • 线程2:打印 System.out.println("Hello from Thread 2!");

并且我计算由线程1和线程2打印的线.但是线程1的线+线程2的线与打印出的总线数不匹配.

这是我的代码:

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Test {

    private static int total = 0;
    private static int countT1 = 0;
    private static int countT2 = 0;
    private boolean run = true;

    public Test() {
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        newCachedThreadPool.execute(t1);
        newCachedThreadPool.execute(t2);
        try {
            Thread.sleep(1000);
        }
        catch (InterruptedException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading

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

如何使用pdfbox将unicode文本写入pdf?

我尝试使用Apache PDFBox 1.8.6在中创建PDF Java。(请参见下面的代码)

如果我写字符串:Hello! 123 abc äöüß一切正常。
但是,如果我添加一个€符号或等效的\ u20ac,字符串就会搞砸了:
þÿ H e l l o ! 1 2 3 a b c ä ö ü ß ¬ ¬ ¦
我认为这与编码有关,因为像OpenOffice这样的程序可以毫无问题地导出带有€或其他Unicode符号的pdf。

那么,我该怎么做才能将Unicode字符串写入PDF?

try {
        PDDocument doc = new PDDocument();
        PDPage page = new PDPage();
        doc.addPage(page);
        PDPageContentStream stream = new PDPageContentStream(doc, page);
        PDFont font = PDType1Font.COURIER;
        //font.setFontEncoding(new EncodingManager().getEncoding(COSName.WIN_ANSI_ENCODING));
        stream.setFont(font, 14);
        stream.beginText();
        stream.setNonStrokingColor(Color.BLACK);
        stream.moveTextPositionByAmount(20, 750);
        String text = "Hello! 123 abc äöüß € \u20ac";
        //JOptionPane.showMessageDialog(null, text);
        stream.drawString(text); …
Run Code Online (Sandbox Code Playgroud)

java pdf pdfbox

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

.htaccess使用哪种正则表达式?

RewriteRule在.htaccess文件中使用哪种正则表达式?

它可能是:PHP preg,但我不确定.

regex .htaccess mod-rewrite

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