从线程更新数组

时间:2017-07-29 18:34:43

标签: java arrays multithreading

我无法理解下面的代码。我的主要问题是为什么用线程中分配给“table”数组的值更新“a”数组。为了更具体,我想解释为什么“a”数组不能打印初始元素(0,1,2,3 ......)。

主要方法和线程的代码:

get '/:id', to: 'post#show'


<html>
<head>
<title>Listing  Reading input from a form </title>
</head>
<body>

Welcome <?php 
    if(isset($_POST['submit'])) 
  {
      session_start(); 
      $user = $_POST['user'];
      echo $user;
      echo "<br><br>Your Email Address is: ".$_POST['address'];
  }
  else 
  {
     echo 'Could not load text!';
  }
 ?>
 <br>



<form action="" method="POST">
<p><strong>Name:</strong><br>
<input type="text" name="user"></p>
<p><strong>Address:</strong><br>
<textarea name="address" rows="5" cols="40"></textarea></p>
<p><input type="submit" value="send" name="submit"></p>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

因为a通过引用传递给SqrtThread的构造函数(搜索按引用传递/按值传递)。在该构造函数中,现在称为array的引用将存储在私有成员table中。但由于它是一个引用,对table的任何更改也将是a中的更改(因为两个引用都指向内存中的相同数组)。

我也应该警告你线程安全等等,但似乎你还在学习基础知识。一旦你获得了这些,你可能想要阅读线程同步,锁,事件等。